1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

HiResTimer: Fix units used for threading policy

The values in mach_timebase_info_data_t should be specified in terms of
'ticks'. On some machines, ticks may correspond to nanoseconds, but this
is not guaranteed.
This commit is contained in:
reuk 2021-01-05 11:01:57 +00:00
parent 857f665f74
commit 452b1bf224
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11

View file

@ -1334,9 +1334,15 @@ private:
const auto thread = pthread_self();
#if JUCE_MAC || JUCE_IOS
mach_timebase_info_data_t timebase;
mach_timebase_info (&timebase);
const auto ticksPerMs = ((double) timebase.denom * 1000000.0) / (double) timebase.numer;
const auto periodTicks = (uint32_t) (ticksPerMs * periodMs);
thread_time_constraint_policy_data_t policy;
policy.period = (uint32_t) (periodMs * 1000000);
policy.computation = 50000;
policy.period = periodTicks;
policy.computation = jmin ((uint32_t) 50000, policy.period);
policy.constraint = policy.period;
policy.preemptible = true;