-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetNormalPriority.c
More file actions
72 lines (60 loc) · 1.75 KB
/
setNormalPriority.c
File metadata and controls
72 lines (60 loc) · 1.75 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <mex.h>
#ifdef __APPLE__
#include <sys/types.h>
#include <sys/sysctl.h>
#include <mach/mach_init.h>
#include <mach/thread_act.h>
#elif defined _WIN32 || defined _WIN64
#include <windows.h>
#elif __linux || __unix || __posix
#endif
#ifdef __APPLE__
void setNormalPriority()
{
thread_standard_policy_data_t policy;
mach_msg_type_number_t count;
boolean_t getDefault;
kern_return_t result;
count = THREAD_STANDARD_POLICY_COUNT;
getDefault = true;
result = thread_policy_get(mach_thread_self(), THREAD_STANDARD_POLICY, (thread_policy_t)&policy, &count, &getDefault);
if (result)
{
mexErrMsgIdAndTxt("priority:failed", "Failed to get normal priority");
}
result = thread_policy_set(mach_thread_self(), THREAD_STANDARD_POLICY, (thread_policy_t)&policy, THREAD_STANDARD_POLICY_COUNT);
if (result)
{
mexErrMsgIdAndTxt("priority:failed", "Failed to set normal priority");
}
}
#elif defined _WIN32 || defined _WIN64
void setNormalPriority()
{
bool result;
result = SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
if (!result)
{
mexErrMsgIdAndTxt("priority:failed", "Failed to set max priority");
}
result = SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
if (!result)
{
mexErrMsgIdAndTxt("priority:failed", "Failed to set max priority");
}
}
#elif __linux || __unix || __posix
void setNormalPriority()
{
mexErrMsgIdAndTxt("priority:failed", "Not implemented for this platform");
}
#endif
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if (nrhs > 0)
{
mexErrMsgIdAndTxt("priority:usage", "Usage: setNormalPriority()");
return;
}
setNormalPriority();
}