38 if (client !=
nullptr)
42 clients.addIfNotAlreadyThere (client);
53 if (clientBeingCalled == client)
60 clients.removeFirstMatchingValue (client);
64 clients.removeFirstMatchingValue (client);
83 if (clients.contains (client))
92 return clients.size();
107 for (
int i = clients.size(); --i >= 0;)
109 auto* c = clients.getUnchecked ((i + index) % clients.size());
111 if (client ==
nullptr || c->nextCallTime < soonest)
114 soonest = c->nextCallTime;
127 int timeToWait = 500;
136 numClients = clients.size();
137 index = numClients > 0 ? ((index + 1) % numClients) : 0;
139 if (
auto* firstClient = getNextClient (index))
140 nextClientTime = firstClient->nextCallTime;
147 if (nextClientTime > now)
149 timeToWait = (int) jmin ((int64) 500, (nextClientTime - now).inMilliseconds());
153 timeToWait = index == 0 ? 1 : 0;
159 clientBeingCalled = getNextClient (index);
162 if (clientBeingCalled !=
nullptr)
164 const int msUntilNextCall = clientBeingCalled->
useTimeSlice();
168 if (msUntilNextCall >= 0)
171 clients.removeFirstMatchingValue (clientBeingCalled);
173 clientBeingCalled =
nullptr;
int getNumClients() const
Returns the number of registered clients.
TimeSliceClient * getClient(int index) const
Returns one of the registered clients.
bool stopThread(int timeOutMilliseconds)
Attempts to stop the thread running.
~TimeSliceThread() override
Destructor.
virtual void run()=0
Must be implemented to perform the thread's actual code.
void removeTimeSliceClient(TimeSliceClient *clientToRemove)
Removes a client from the list.
void notify() const
Wakes up the thread.
static RelativeTime milliseconds(int milliseconds) noexcept
Creates a new RelativeTime object representing a number of milliseconds.
static Time JUCE_CALLTYPE getCurrentTime() noexcept
Returns a Time object that is set to the current system time.
virtual int useTimeSlice()=0
Called back by a TimeSliceThread.
Used by the TimeSliceThread class.
bool threadShouldExit() const
Checks whether the thread has been told to stop running.
void addTimeSliceClient(TimeSliceClient *clientToAdd, int millisecondsBeforeStarting=0)
Adds a client to the list.
void removeAllClients()
Removes all the active and pending clients from the list.
Holds an absolute date and time.
Automatically locks and unlocks a mutex object.
TimeSliceThread(const String &threadName)
Creates a TimeSliceThread.
bool wait(int timeOutMilliseconds) const
Suspends the execution of this thread until either the specified timeout period has elapsed...
Automatically unlocks and re-locks a mutex object.
void moveToFrontOfQueue(TimeSliceClient *clientToMove)
If the given client is waiting in the queue, it will be moved to the front and given a time-slice as ...