46 static constexpr size_t osDefaultStackSize { 0 };
98 jassert (newProcessingTimeMs > 0.0);
99 return withMember (*
this, &RealtimeOptions::processingTimeMs, newProcessingTimeMs);
110 jassert (newMaximumProcessingTimeMs > 0.0);
111 return withMember (*
this, &RealtimeOptions::maximumProcessingTimeMs, newMaximumProcessingTimeMs);
129 const auto approxFrameTimeMs = (samplesPerFrame / sampleRate) * 1000.0;
130 return withMaximumProcessingTimeMs (approxFrameTimeMs);
144 return withMember (*
this, &RealtimeOptions::periodMs, newPeriodMs);
158 return withPeriodMs (1'000.0 / newPeriodHz);
177 return processingTimeMs;
187 return maximumProcessingTimeMs;
220 explicit Thread (
const String& threadName,
size_t threadStackSize = osDefaultStackSize);
274 bool startThread (
Priority newPriority);
309 bool stopThread (
int timeOutMilliseconds);
352 bool isThreadRunning()
const;
365 void signalThreadShouldExit();
374 bool threadShouldExit()
const;
382 static bool currentThreadShouldExit();
391 bool waitForThreadToExit (
int timeOutMilliseconds)
const;
417 bool isRealtime()
const;
427 void setAffinityMask (
uint32 affinityMask);
462 bool wait (
double timeOutMilliseconds)
const;
503 ThreadID getThreadId() const noexcept;
506 const
String& getThreadName() const noexcept {
return threadName; }
514 #if JUCE_ANDROID || DOXYGEN
579 bool setPriority (
Priority newPriority);
587 CriticalSection startStopLock;
588 WaitableEvent startSuspensionEvent, defaultEvent;
589 size_t threadStackSize;
590 uint32 affinityMask = 0;
591 bool deleteOnThreadEnd =
false;
593 ListenerList<Listener, Array<Listener*, CriticalSection>> listeners;
595 #if JUCE_ANDROID || JUCE_LINUX || JUCE_BSD
600 friend void JUCE_API juce_threadEntryPoint (
void*);
603 bool startThreadInternal (Priority);
604 bool createNativeThread (Priority);
605 void closeThreadHandle();
607 void threadEntryPoint();
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.
void * ThreadID
A value type used for thread IDs.
virtual void run()=0
Must be implemented to perform the thread's actual code.
Priority
The different runtime priorities of non-realtime threads.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
Object withMember(Object copy, Member OtherObject::*member, Other &&value)
Copies an object, sets one of the copy's members to the specified value, and then returns the copy.
bool isPositiveAndNotGreaterThan(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also less than or equal to a specified upper limit.
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
A selection of options available when creating realtime threads.
RealtimeOptions withPeriodHz(double newPeriodHz) const
Specify the approximate frequency at which the thread will be woken up.
std::optional< double > getMaximumProcessingTimeMs() const
Returns the maximum amount of processing time required each time the thread wakes up.
RealtimeOptions withPeriodMs(double newPeriodMs) const
Specify the approximate amount of time between each thread wake up.
RealtimeOptions withMaximumProcessingTimeMs(double newMaximumProcessingTimeMs) const
Specify the maximum amount of processing time required each time the thread wakes up.
std::optional< double > getPeriodMs() const
Returns the approximate amount of time between each thread wake up, or nullopt if there is no inheren...
RealtimeOptions withApproximateAudioProcessingTime(int samplesPerFrame, double sampleRate) const
Specify the maximum amount of processing time required each time the thread wakes up.
std::optional< double > getProcessingTimeMs() const
Returns the expected amount of processing time required each time the thread wakes up.
RealtimeOptions withPriority(int newPriority) const
A value with a range of 0-10, where 10 is the highest priority.
int getPriority() const
Returns a value with a range of 0-10, where 10 is the highest priority.
RealtimeOptions withProcessingTimeMs(double newProcessingTimeMs) const
Specify the expected amount of processing time required each time the thread wakes up.