OpenShot Library | libopenshot-audio 0.2.0
juce::TimeSliceThread Class Reference

A thread that keeps a list of clients, and calls each one in turn, giving them all a chance to run some sort of short task. More...

#include <juce_TimeSliceThread.h>

+ Inheritance diagram for juce::TimeSliceThread:

Public Member Functions

 TimeSliceThread (const String &threadName)
 Creates a TimeSliceThread.
 
 ~TimeSliceThread () override
 Destructor.
 
void addTimeSliceClient (TimeSliceClient *clientToAdd, int millisecondsBeforeStarting=0)
 Adds a client to the list.
 
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 soon as possible.
 
void removeTimeSliceClient (TimeSliceClient *clientToRemove)
 Removes a client from the list.
 
void removeAllClients ()
 Removes all the active and pending clients from the list.
 
int getNumClients () const
 Returns the number of registered clients.
 
TimeSliceClientgetClient (int index) const
 Returns one of the registered clients.
 
- Public Member Functions inherited from juce::Thread
 Thread (const String &threadName, size_t threadStackSize=0)
 Creates a thread.
 
virtual ~Thread ()
 Destructor.
 
virtual void run ()=0
 Must be implemented to perform the thread's actual code.
 
void startThread ()
 Starts the thread running.
 
void startThread (int priority)
 Starts the thread with a given priority.
 
bool stopThread (int timeOutMilliseconds)
 Attempts to stop the thread running.
 
bool isThreadRunning () const
 Returns true if the thread is currently active.
 
void signalThreadShouldExit ()
 Sets a flag to tell the thread it should stop.
 
bool threadShouldExit () const
 Checks whether the thread has been told to stop running.
 
bool waitForThreadToExit (int timeOutMilliseconds) const
 Waits for the thread to stop.
 
void addListener (Listener *)
 Add a listener to this thread which will receive a callback when signalThreadShouldExit was called on this thread.
 
void removeListener (Listener *)
 Removes a listener added with addListener.
 
bool setPriority (int priority)
 Changes the thread's priority.
 
void setAffinityMask (uint32 affinityMask)
 Sets the affinity mask for the thread.
 
bool wait (int timeOutMilliseconds) const
 Suspends the execution of this thread until either the specified timeout period has elapsed, or another thread calls the notify() method to wake it up.
 
void notify () const
 Wakes up the thread.
 
ThreadID getThreadId () const noexcept
 Returns the ID of this thread.
 
const StringgetThreadName () const noexcept
 Returns the name of the thread.
 

Additional Inherited Members

- Public Types inherited from juce::Thread
enum  { realtimeAudioPriority = -1 }
 Special realtime audio thread priority. More...
 
using ThreadID = void *
 A value type used for thread IDs.
 
- Static Public Member Functions inherited from juce::Thread
static void launch (std::function< void()> functionToRun)
 Invokes a lambda or function on its own thread.
 
static bool currentThreadShouldExit ()
 Checks whether the current thread has been told to stop running.
 
static bool setCurrentThreadPriority (int priority)
 Changes the priority of the caller thread.
 
static void JUCE_CALLTYPE setCurrentThreadAffinityMask (uint32 affinityMask)
 Changes the affinity mask for the caller thread.
 
static void JUCE_CALLTYPE sleep (int milliseconds)
 Suspends the execution of the current thread until the specified timeout period has elapsed (note that this may not be exact).
 
static void JUCE_CALLTYPE yield ()
 Yields the current thread's CPU time-slot and allows a new thread to run.
 
static ThreadID JUCE_CALLTYPE getCurrentThreadId ()
 Returns an id that identifies the caller thread.
 
static Thread *JUCE_CALLTYPE getCurrentThread ()
 Finds the thread object that is currently running.
 
static void JUCE_CALLTYPE setCurrentThreadName (const String &newThreadName)
 Changes the name of the caller thread.
 
static void initialiseJUCE (void *jniEnv, void *jContext)
 Initialises the JUCE subsystem for projects not created by the Projucer.
 

Detailed Description

A thread that keeps a list of clients, and calls each one in turn, giving them all a chance to run some sort of short task.

See also
TimeSliceClient, Thread

Definition at line 86 of file juce_TimeSliceThread.h.

Constructor & Destructor Documentation

◆ TimeSliceThread()

juce::TimeSliceThread::TimeSliceThread ( const String threadName)
explicit

Creates a TimeSliceThread.

When first created, the thread is not running. Use the startThread() method to start it.

Definition at line 26 of file juce_TimeSliceThread.cpp.

◆ ~TimeSliceThread()

juce::TimeSliceThread::~TimeSliceThread ( )
override

Destructor.

Deleting a Thread object that is running will only give the thread a brief opportunity to stop itself cleanly, so it's recommended that you should always call stopThread() with a decent timeout before deleting, to avoid the thread being forcibly killed (which is a Bad Thing).

Definition at line 30 of file juce_TimeSliceThread.cpp.

References juce::Thread::stopThread().

Member Function Documentation

◆ addTimeSliceClient()

void juce::TimeSliceThread::addTimeSliceClient ( TimeSliceClient clientToAdd,
int  millisecondsBeforeStarting = 0 
)

Adds a client to the list.

The client's callbacks will start after the number of milliseconds specified by millisecondsBeforeStarting (and this may happen before this method has returned).

Definition at line 36 of file juce_TimeSliceThread.cpp.

References juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::addIfNotAlreadyThere(), juce::Time::getCurrentTime(), juce::RelativeTime::milliseconds(), and juce::Thread::notify().

Referenced by juce::BufferingAudioReader::BufferingAudioReader(), and juce::BufferingAudioSource::prepareToPlay().

◆ moveToFrontOfQueue()

void juce::TimeSliceThread::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 soon as possible.

If the specified client has not been added, nothing will happen.

Definition at line 79 of file juce_TimeSliceThread.cpp.

References juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::contains(), juce::Time::getCurrentTime(), and juce::Thread::notify().

Referenced by juce::BufferingAudioSource::prepareToPlay(), and juce::BufferingAudioSource::setNextReadPosition().

◆ removeTimeSliceClient()

void juce::TimeSliceThread::removeTimeSliceClient ( TimeSliceClient clientToRemove)

Removes a client from the list.

This method will make sure that all callbacks to the client have completely finished before the method returns.

Definition at line 47 of file juce_TimeSliceThread.cpp.

References juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::removeFirstMatchingValue().

Referenced by juce::BufferingAudioSource::prepareToPlay(), juce::BufferingAudioSource::releaseResources(), and removeAllClients().

◆ removeAllClients()

void juce::TimeSliceThread::removeAllClients ( )

Removes all the active and pending clients from the list.

This method will make sure that all callbacks to clients have finished before the method returns.

Definition at line 68 of file juce_TimeSliceThread.cpp.

References getClient(), and removeTimeSliceClient().

◆ getNumClients()

int juce::TimeSliceThread::getNumClients ( ) const

Returns the number of registered clients.

Definition at line 90 of file juce_TimeSliceThread.cpp.

References juce::Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::size().

◆ getClient()

TimeSliceClient * juce::TimeSliceThread::getClient ( int  index) const

Returns one of the registered clients.

Definition at line 95 of file juce_TimeSliceThread.cpp.

Referenced by removeAllClients().


The documentation for this class was generated from the following files: