3#include <ossia/detail/sleep.hpp>
12struct priority_boost_handle
15 explicit priority_boost_handle(
double frequencyHz)
22 m_mmcss = AvSetMmThreadCharacteristicsW(L
"Pro Audio", &taskIndex);
25 AvSetMmThreadPriority(m_mmcss, AVRT_PRIORITY_CRITICAL);
27#elif defined(__APPLE__)
30 mach_port_t threadPort = pthread_mach_thread_np(pthread_self());
33 double periodNs = 1'000'000'000.0 / frequencyHz;
34 uint32_t periodMach =
static_cast<uint32_t
>(periodNs * detail::g_timebase_info.denom / detail::g_timebase_info.numer);
36 thread_time_constraint_policy_data_t policy;
37 policy.period = periodMach;
38 policy.computation = periodMach / 10;
39 policy.constraint = periodMach / 2;
40 policy.preemptible = 1;
42 kern_return_t kr = thread_policy_set(
44 THREAD_TIME_CONSTRAINT_POLICY,
45 reinterpret_cast<thread_policy_t
>(&policy),
46 THREAD_TIME_CONSTRAINT_POLICY_COUNT
49 m_policy_set = (kr == KERN_SUCCESS);
54 pthread_set_qos_class_self_np(QOS_CLASS_USER_INTERACTIVE, 0);
58 pthread_getschedparam(pthread_self(), &m_original_policy, &m_original_param);
61 struct sched_param param;
62 param.sched_priority = sched_get_priority_max(SCHED_FIFO);
64 if (pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m) == 0)
71 setpriority(PRIO_PROCESS, 0, -20);
76 ~priority_boost_handle()
81 AvRevertMmThreadCharacteristics(m_mmcss);
84#elif defined(__APPLE__)
88 mach_port_t threadPort = pthread_mach_thread_np(pthread_self());
89 thread_standard_policy_data_t policy;
92 THREAD_STANDARD_POLICY,
93 reinterpret_cast<thread_policy_t
>(&policy),
94 THREAD_STANDARD_POLICY_COUNT
101 pthread_setschedparam(pthread_self(), m_original_policy, &m_original_param);
109 HANDLE m_mmcss =
nullptr;
110 UINT m_timer_resolution = 1;
111#elif defined(__APPLE__)
112 bool m_policy_set =
false;
114 int m_original_policy = SCHED_OTHER;
115 struct sched_param m_original_param = {};
116 bool m_elevated =
false;