LMMS
Loading...
Searching...
No Matches
juce_Thread.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
43{
44public:
45 //==============================================================================
58 explicit Thread (const String& threadName, size_t threadStackSize = 0);
59
67 virtual ~Thread();
68
69 //==============================================================================
78 virtual void run() = 0;
79
80 //==============================================================================
88 void startThread();
89
97 void startThread (int priority);
98
119 bool stopThread (int timeOutMilliseconds);
120
121 //==============================================================================
133 static void launch (std::function<void()> functionToRun);
134
135 //==============================================================================
137 bool isThreadRunning() const;
138
151
159 bool threadShouldExit() const;
160
167 static bool currentThreadShouldExit();
168
176 bool waitForThreadToExit (int timeOutMilliseconds) const;
177
178 //==============================================================================
181 {
182 public:
183 virtual ~Listener() = default;
184
188 virtual void exitSignalSent() = 0;
189 };
190
196 void addListener (Listener*);
197
199 void removeListener (Listener*);
200
201 //==============================================================================
222 enum
223 {
225 };
226
235 bool setPriority (int priority);
236
244 static bool setCurrentThreadPriority (int priority);
245
246 //==============================================================================
254 void setAffinityMask (uint32 affinityMask);
255
262 static void JUCE_CALLTYPE setCurrentThreadAffinityMask (uint32 affinityMask);
263
264 //==============================================================================
272 static void JUCE_CALLTYPE sleep (int milliseconds);
273
279 static void JUCE_CALLTYPE yield();
280
281 //==============================================================================
289 bool wait (int timeOutMilliseconds) const;
290
297 void notify() const;
298
299 //==============================================================================
304 using ThreadID = void*;
305
314
321
331
334
339 static void JUCE_CALLTYPE setCurrentThreadName (const String& newThreadName);
340
341 #if JUCE_ANDROID || DOXYGEN
342 //==============================================================================
380 static void initialiseJUCE (void* jniEnv, void* jContext);
381 #endif
382
383private:
384 //==============================================================================
393 bool deleteOnThreadEnd = false;
396
397 #if JUCE_ANDROID
398 bool isAndroidRealtimeThread = false;
399 #endif
400
401 #ifndef DOXYGEN
402 friend void JUCE_API juce_threadEntryPoint (void*);
403 #endif
404
405 void launchThread();
406 void closeThreadHandle();
407 void killThread();
408 void threadEntryPoint();
409 static bool setThreadPriority (void*, int);
410 static int getAdjustedPriority (int);
411
413};
414
415} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
Definition juce_CriticalSection.h:43
Definition juce_ListenerList.h:70
Definition juce_String.h:53
Definition juce_Thread.h:181
virtual void exitSignalSent()=0
virtual ~Listener()=default
size_t threadStackSize
Definition juce_Thread.h:391
void * ThreadID
Definition juce_Thread.h:304
static Thread *JUCE_CALLTYPE getCurrentThread()
Definition juce_Thread.cpp:160
Atomic< void * > threadHandle
Definition juce_Thread.h:386
void startThread()
Definition juce_Thread.cpp:122
void launchThread()
Definition juce_posix_SharedCode.h:918
CriticalSection startStopLock
Definition juce_Thread.h:388
ListenerList< Listener, Array< Listener *, CriticalSection > > listeners
Definition juce_Thread.h:395
void threadEntryPoint()
Definition juce_Thread.cpp:79
ThreadID getThreadId() const noexcept
Definition juce_Thread.cpp:165
bool waitForThreadToExit(int timeOutMilliseconds) const
Definition juce_Thread.cpp:190
@ realtimeAudioPriority
Definition juce_Thread.h:224
virtual void run()=0
Thread(const String &threadName, size_t threadStackSize=0)
Definition juce_Thread.cpp:26
static bool currentThreadShouldExit()
Definition juce_Thread.cpp:182
bool threadShouldExit() const
Definition juce_Thread.cpp:177
bool deleteOnThreadEnd
Definition juce_Thread.h:393
void killThread()
Definition juce_posix_SharedCode.h:963
WaitableEvent defaultEvent
Definition juce_Thread.h:389
static ThreadID JUCE_CALLTYPE getCurrentThreadId()
Definition juce_posix_SharedCode.h:1028
WaitableEvent startSuspensionEvent
Definition juce_Thread.h:389
const String & getThreadName() const noexcept
Definition juce_Thread.h:333
static bool setThreadPriority(void *, int)
Definition juce_posix_SharedCode.h:993
bool stopThread(int timeOutMilliseconds)
Definition juce_Thread.cpp:208
void addListener(Listener *)
Definition juce_Thread.cpp:242
static int getAdjustedPriority(int)
Definition juce_Thread.cpp:293
friend void JUCE_API juce_threadEntryPoint(void *)
Definition juce_Thread.cpp:116
Atomic< int32 > shouldExit
Definition juce_Thread.h:394
void signalThreadShouldExit()
Definition juce_Thread.cpp:171
Atomic< ThreadID > threadId
Definition juce_Thread.h:387
void closeThreadHandle()
Definition juce_posix_SharedCode.h:957
int threadPriority
Definition juce_Thread.h:390
bool isThreadRunning() const
Definition juce_Thread.cpp:155
uint32 affinityMask
Definition juce_Thread.h:392
const String threadName
Definition juce_Thread.h:385
void removeListener(Listener *)
Definition juce_Thread.cpp:247
static void launch(std::function< void()> functionToRun)
Definition juce_Thread.cpp:325
Definition juce_WaitableEvent.h:36
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define JUCE_CALLTYPE
#define JUCE_API
Definition juce_StandardHeader.h:152
Definition carla_juce.cpp:31
unsigned int uint32
Definition juce_MathsFunctions.h:45
Definition juce_Atomic.h:42
#define const
Definition zconf.h:137