62 explicit Thread (
const String& threadName,
size_t threadStackSize = 0);
82 virtual void run() = 0;
101 void startThread (
int priority);
123 bool stopThread (
int timeOutMilliseconds);
137 static void launch (std::function<
void()> functionToRun);
141 bool isThreadRunning()
const;
154 void signalThreadShouldExit();
163 bool threadShouldExit()
const;
171 static bool currentThreadShouldExit();
180 bool waitForThreadToExit (
int timeOutMilliseconds)
const;
228 realtimeAudioPriority = -1
239 bool setPriority (
int priority);
248 static bool setCurrentThreadPriority (
int priority);
258 void setAffinityMask (uint32 affinityMask);
276 static void JUCE_CALLTYPE
sleep (
int milliseconds);
293 bool wait (
int timeOutMilliseconds)
const;
324 static Thread* JUCE_CALLTYPE getCurrentThread();
334 ThreadID getThreadId() const noexcept;
337 const
String& getThreadName() const noexcept {
return threadName; }
345 #if JUCE_ANDROID || defined (DOXYGEN)
392 CriticalSection startStopLock;
393 WaitableEvent startSuspensionEvent, defaultEvent;
394 int threadPriority = 5;
395 size_t threadStackSize;
396 uint32 affinityMask = 0;
397 bool deleteOnThreadEnd =
false;
398 Atomic<int32> shouldExit { 0 };
399 ListenerList<Listener, Array<Listener*, CriticalSection>> listeners;
402 bool isAndroidRealtimeThread =
false;
406 friend void JUCE_API juce_threadEntryPoint (
void*);
410 void closeThreadHandle();
412 void threadEntryPoint();
413 static bool setThreadPriority (
void*,
int);
415 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Thread)
Used to receive callbacks for thread exit calls.
virtual void exitSignalSent()=0
Called if Thread::signalThreadShouldExit was called.
static void initialiseJUCE(void *jniEnv, void *jContext)
Initialises the JUCE subsystem for projects not created by the Projucer.
static void JUCE_CALLTYPE setCurrentThreadAffinityMask(uint32 affinityMask)
Changes the affinity mask for the caller thread.
void * ThreadID
A value type used for thread IDs.
static void JUCE_CALLTYPE sleep(int milliseconds)
Suspends the execution of the current thread until the specified timeout period has elapsed (note tha...
static void JUCE_CALLTYPE setCurrentThreadName(const String &newThreadName)
Changes the name of the caller thread.
virtual void run()=0
Must be implemented to perform the thread's actual code.
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.
#define JUCE_API
This macro is added to all JUCE public class declarations.
A simple wrapper around std::atomic.