46 static constexpr size_t osDefaultStackSize { 0 };
86 jassert (isPositiveAndNotGreaterThan (newPriority, 10));
87 return withMember (*
this, &RealtimeOptions::priority, juce::jlimit (0, 10, newPriority));
98 jassert (newProcessingTimeMs > 0.0);
99 return withMember (*
this, &RealtimeOptions::processingTimeMs, newProcessingTimeMs);
110 jassert (newMaximumProcessingTimeMs > 0.0);
111 return withMember (*
this, &RealtimeOptions::maximumProcessingTimeMs, newMaximumProcessingTimeMs);
126 jassert (samplesPerFrame > 0);
127 jassert (sampleRate > 0.0);
129 const auto approxFrameTimeMs = (samplesPerFrame / sampleRate) * 1000.0;
130 return withMaximumProcessingTimeMs (approxFrameTimeMs);
143 jassert (newPeriodMs > 0.0);
144 return withMember (*
this, &RealtimeOptions::periodMs, newPeriodMs);
157 jassert (newPeriodHz > 0.0);
158 return withPeriodMs (1'000.0 / newPeriodHz);
177 return processingTimeMs;
187 return maximumProcessingTimeMs;
202 std::optional<double> processingTimeMs;
203 std::optional<double> maximumProcessingTimeMs;
204 std::optional<double> periodMs{};
220 explicit Thread (
const String& threadName,
size_t threadStackSize = osDefaultStackSize);
274 bool startThread (
Priority newPriority);
309 bool stopThread (
int timeOutMilliseconds);
329 static bool launch (std::function<
void()> functionToRun);
348 static bool launch (
Priority priority, std::function<
void()> functionToRun);
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);
445 static void JUCE_CALLTYPE
sleep (
int milliseconds);
462 bool wait (
double timeOutMilliseconds)
const;
493 static Thread* JUCE_CALLTYPE getCurrentThread();
503 ThreadID getThreadId() const noexcept;
506 const
String& getThreadName() const noexcept {
return threadName; }
514 #if JUCE_ANDROID || DOXYGEN
553 static void initialiseJUCE (
void* jniEnv,
void* jContext);
584 std::atomic<void*> threadHandle {
nullptr };
585 std::atomic<ThreadID> threadId {
nullptr };
586 std::optional<RealtimeOptions> realtimeOptions = {};
587 CriticalSection startStopLock;
588 WaitableEvent startSuspensionEvent, defaultEvent;
589 size_t threadStackSize;
590 uint32 affinityMask = 0;
591 bool deleteOnThreadEnd =
false;
592 std::atomic<bool> shouldExit {
false };
593 ListenerList<Listener, Array<Listener*, CriticalSection>> listeners;
595 #if JUCE_ANDROID || JUCE_LINUX || JUCE_BSD
596 std::atomic<Priority> priority;
600 friend void JUCE_API juce_threadEntryPoint (
void*);
603 bool startThreadInternal (Priority);
604 bool createNativeThread (Priority);
605 void closeThreadHandle();
607 void threadEntryPoint();
609 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Thread)