-
Notifications
You must be signed in to change notification settings - Fork 7
/
pri.c
32 lines (27 loc) · 829 Bytes
/
pri.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <mach/mach_init.h>
#include <mach/thread_act.h>
// Obtained from the Stage psychophysics suite for Matlab.
void setMaxPriority()
{
int mib[2];
int busFreq;
size_t len;
thread_time_constraint_policy_data_t policy;
kern_return_t result;
mib[0] = CTL_HW;
mib[1] = HW_BUS_FREQ;
len = sizeof(busFreq);
sysctl(mib, 2, &busFreq, &len, NULL, 0);
policy.period = busFreq / 120;
policy.computation = policy.period * 0.9;
policy.constraint = policy.computation;
policy.preemptible = 1;
result = thread_policy_set(mach_thread_self(), THREAD_TIME_CONSTRAINT_POLICY, (thread_policy_t)&policy, THREAD_TIME_CONSTRAINT_POLICY_COUNT);
if (result)
{
printf("Failed to set max priority");
}
}