14 #include <mrpt/config.h> 16 #ifdef MRPT_OS_WINDOWS 23 #include <sys/select.h> 33 #include <sys/types.h> 36 #include <sys/sysctl.h> 37 #include <mach/mach_init.h> 38 #include <mach/thread_act.h> 45 #ifdef MRPT_OS_WINDOWS 47 SetThreadPriority(GetCurrentThread(), priority);
51 reinterpret_cast<long unsigned int>(pthread_self());
57 struct sched_param
param;
59 if (0 != (ret = pthread_getschedparam(tid, &policy, &
param)))
62 <<
"[mrpt::system::changeThreadPriority] Warning: Failed call to " 63 "pthread_getschedparam (error: `" 64 << strerror(ret) <<
"`)" << std::endl;
69 int min_prio = sched_get_priority_min(policy),
70 max_prio = sched_get_priority_max(policy);
71 if (min_prio < 0) min_prio = 1;
72 if (max_prio < 0) max_prio = 99;
81 prio = (max_prio + 3 * min_prio) / 4;
84 prio = (max_prio + 2 * min_prio) / 3;
87 prio = (max_prio + min_prio) / 2;
90 prio = (2 * max_prio + min_prio) / 3;
93 prio = (3 * max_prio + min_prio) / 4;
100 param.sched_priority = prio;
101 if (0 != (ret = pthread_setschedparam(tid, policy, &
param)))
104 <<
"[mrpt::system::changeThreadPriority] Warning: Failed call to " 105 "pthread_setschedparam (error: `" 106 << strerror(ret) <<
"`)" << std::endl;
114 #ifdef MRPT_OS_WINDOWS 119 dwPri = IDLE_PRIORITY_CLASS;
122 dwPri = NORMAL_PRIORITY_CLASS;
125 dwPri = HIGH_PRIORITY_CLASS;
128 dwPri = REALTIME_PRIORITY_CLASS;
133 SetPriorityClass(GetCurrentProcess(), dwPri);
154 const int ret = nice(nice_val);
155 if (ret == -1 && errno == EPERM)
157 std::cerr <<
"[mrpt::system::changeCurrentProcessPriority] Error " 158 "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.