12 #include <mrpt/config.h> 16 #ifdef MRPT_OS_WINDOWS 23 #include <sys/select.h> 34 #include <sys/types.h> 36 #include <mach/mach_init.h> 37 #include <mach/thread_act.h> 38 #include <sys/sysctl.h> 45 #ifdef MRPT_OS_WINDOWS 47 SetThreadPriority(GetCurrentThread(), priority);
49 const pthread_t tid = pthread_self();
52 struct sched_param param
56 if (0 != (ret = pthread_getschedparam(tid, &policy, ¶m)))
59 <<
"[mrpt::system::changeThreadPriority] Warning: Failed call to " 60 "pthread_getschedparam (error: `" 61 << strerror(ret) <<
"`)" << std::endl;
66 int min_prio = sched_get_priority_min(policy),
67 max_prio = sched_get_priority_max(policy);
68 if (min_prio < 0) min_prio = 1;
69 if (max_prio < 0) max_prio = 99;
78 prio = (max_prio + 3 * min_prio) / 4;
81 prio = (max_prio + 2 * min_prio) / 3;
84 prio = (max_prio + min_prio) / 2;
87 prio = (2 * max_prio + min_prio) / 3;
90 prio = (3 * max_prio + min_prio) / 4;
97 param.sched_priority = prio;
98 if (0 != (ret = pthread_setschedparam(tid, policy, ¶m)))
101 <<
"[mrpt::system::changeThreadPriority] Warning: Failed call to " 102 "pthread_setschedparam (error: `" 103 << strerror(ret) <<
"`)" << std::endl;
111 #ifdef MRPT_OS_WINDOWS 116 dwPri = IDLE_PRIORITY_CLASS;
119 dwPri = NORMAL_PRIORITY_CLASS;
122 dwPri = HIGH_PRIORITY_CLASS;
125 dwPri = REALTIME_PRIORITY_CLASS;
130 SetPriorityClass(GetCurrentProcess(), dwPri);
151 const int ret = nice(nice_val);
152 if (ret == -1 && errno == EPERM)
154 std::cerr <<
"[mrpt::system::changeCurrentProcessPriority] Error " 155 "calling nice(): Not enough permissions.\n";
void changeCurrentThreadPriority(TThreadPriority priority)
Change the priority of the current thread - for Windows, see also changeCurrentProcessPriority() ...
#define THROW_EXCEPTION(msg)
Win32: THREAD_PRIORITY_ABOVE_NORMAL.
void changeCurrentProcessPriority(TProcessPriority priority)
Change the priority of the given process (it applies to all the threads, plus independent modifiers f...
TProcessPriority
The type for cross-platform process (application) priorities.
Win32: THREAD_PRIORITY_LOWEST.
Win32: THREAD_PRIORITY_IDLE.
Win32: THREAD_PRIORITY_NORMAL.
TThreadPriority
The type for cross-platform thread priorities.
Win32: THREAD_PRIORITY_TIME_CRITICAL.
Win32: THREAD_PRIORITY_HIGHEST.
Win32: THREAD_PRIORITY_BELOW_NORMAL.