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;
134 const ScopedLock sl2 (listLock);
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;
155 const ScopedLock sl (callbackLock);
158 const ScopedLock sl2 (listLock);
159 clientBeingCalled = getNextClient (index);
162 if (clientBeingCalled !=
nullptr)
164 const int msUntilNextCall = clientBeingCalled->
useTimeSlice();
166 const ScopedLock sl2 (listLock);
168 if (msUntilNextCall >= 0)
171 clients.removeFirstMatchingValue (clientBeingCalled);
173 clientBeingCalled =
nullptr;
Automatically locks and unlocks a mutex object.
Automatically unlocks and re-locks a mutex object.
static RelativeTime milliseconds(int milliseconds) noexcept
Creates a new RelativeTime object representing a number of milliseconds.
bool wait(int timeOutMilliseconds) const
Suspends the execution of this thread until either the specified timeout period has elapsed,...
virtual void run()=0
Must be implemented to perform the thread's actual code.
bool threadShouldExit() const
Checks whether the thread has been told to stop running.
bool stopThread(int timeOutMilliseconds)
Attempts to stop the thread running.
void notify() const
Wakes up the thread.
Used by the TimeSliceThread class.
virtual int useTimeSlice()=0
Called back by a TimeSliceThread.
int getNumClients() const
Returns the number of registered clients.
void removeTimeSliceClient(TimeSliceClient *clientToRemove)
Removes a client from the list.
void addTimeSliceClient(TimeSliceClient *clientToAdd, int millisecondsBeforeStarting=0)
Adds a client to the list.
~TimeSliceThread() override
Destructor.
TimeSliceClient * getClient(int index) const
Returns one of the registered clients.
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 ...
void removeAllClients()
Removes all the active and pending clients from the list.
TimeSliceThread(const String &threadName)
Creates a TimeSliceThread.
Holds an absolute date and time.
static Time JUCE_CALLTYPE getCurrentTime() noexcept
Returns a Time object that is set to the current system time.