17namespace tracktion {
inline namespace graph
21 bool setThreadPriority (
void* handle,
int priority)
23 assert (handle !=
nullptr);
24 int pri = THREAD_PRIORITY_TIME_CRITICAL;
26 if (priority < 1) pri = THREAD_PRIORITY_IDLE;
27 else if (priority < 2) pri = THREAD_PRIORITY_LOWEST;
28 else if (priority < 5) pri = THREAD_PRIORITY_BELOW_NORMAL;
29 else if (priority < 7) pri = THREAD_PRIORITY_NORMAL;
30 else if (priority < 9) pri = THREAD_PRIORITY_ABOVE_NORMAL;
31 else if (priority < 10) pri = THREAD_PRIORITY_HIGHEST;
33 return SetThreadPriority (handle, pri) != FALSE;
36 template<
typename HandleType>
37 bool setThreadPriority (HandleType handle,
int priority)
39 assert (handle != HandleType());
41 struct sched_param param;
45 if (pthread_getschedparam ((pthread_t) handle, &policy, ¶m) != 0)
48 policy = priority == 0 ? SCHED_OTHER : SCHED_RR;
53 param.sched_priority = ((maxPriority - minPriority) * priority) / 10 + minPriority;
54 return pthread_setschedparam ((pthread_t) handle, policy, ¶m) == 0;
59 template<
typename Type>
62 for (
const auto& optional : optionals)
63 if (optional.has_value())
73 const auto processingTimeMs = firstOptionalWithValue (
84 jassert (maxProcessingTimeMs >= processingTimeMs);
86 thread_time_constraint_policy_data_t policy;
90 policy.preemptible =
true;
92 const auto result = thread_policy_set (pthread_mach_thread_np (
pthread_self()),
93 THREAD_TIME_CONSTRAINT_POLICY,
94 (thread_policy_t) &policy,
95 THREAD_TIME_CONSTRAINT_POLICY_COUNT);
97 if (result == KERN_SUCCESS)
119 return setThreadPriority (t.native_handle(), priority);
static int64 secondsToHighResolutionTicks(double seconds) noexcept
bool tryToUpgradeCurrentThreadToRealtime(const juce::Thread::RealtimeOptions &)
Tries to upgrade the current thread to realtime priority.
std::optional< double > getMaximumProcessingTimeMs() const
std::optional< double > getPeriodMs() const
std::optional< double > getProcessingTimeMs() const
RealtimeOptions withProcessingTimeMs(double newProcessingTimeMs) const