Skip to content

Commit a8eb930

Browse files
committed
changed thread enum
Signed-off-by: Martin Mayer <[email protected]>
1 parent 61c09b2 commit a8eb930

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

include/rcutils/thread.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,35 @@ extern "C"
2626
/// Enum for OS independent thread priorities
2727
enum ThreadPriority
2828
{
29+
THREAD_PRIORITY_LOWEST,
30+
THREAD_PRIORITY_LOWEST_PLUS1,
31+
THREAD_PRIORITY_LOWEST_PLUS2,
32+
THREAD_PRIORITY_LOWEST_PLUS3,
33+
THREAD_PRIORITY_LOW_MINUS3,
34+
THREAD_PRIORITY_LOW_MINUS2,
35+
THREAD_PRIORITY_LOW_MINUS1,
2936
THREAD_PRIORITY_LOW,
3037
THREAD_PRIORITY_LOW_PLUS1,
3138
THREAD_PRIORITY_LOW_PLUS2,
3239
THREAD_PRIORITY_LOW_PLUS3,
33-
THREAD_PRIORITY_LOW_PLUS4,
34-
THREAD_PRIORITY_LOW_PLUS5,
35-
THREAD_PRIORITY_MEDIUM_MINUS5,
36-
THREAD_PRIORITY_MEDIUM_MINUS4,
3740
THREAD_PRIORITY_MEDIUM_MINUS3,
3841
THREAD_PRIORITY_MEDIUM_MINUS2,
3942
THREAD_PRIORITY_MEDIUM_MINUS1,
4043
THREAD_PRIORITY_MEDIUM,
4144
THREAD_PRIORITY_MEDIUM_PLUS1,
4245
THREAD_PRIORITY_MEDIUM_PLUS2,
4346
THREAD_PRIORITY_MEDIUM_PLUS3,
44-
THREAD_PRIORITY_MEDIUM_PLUS4,
45-
THREAD_PRIORITY_MEDIUM_PLUS5,
46-
THREAD_PRIORITY_HIGH_MINUS5,
47-
THREAD_PRIORITY_HIGH_MINUS4,
4847
THREAD_PRIORITY_HIGH_MINUS3,
4948
THREAD_PRIORITY_HIGH_MINUS2,
5049
THREAD_PRIORITY_HIGH_MINUS1,
51-
THREAD_PRIORITY_HIGH
50+
THREAD_PRIORITY_HIGH,
51+
THREAD_PRIORITY_HIGH_PLUS1,
52+
THREAD_PRIORITY_HIGH_PLUS2,
53+
THREAD_PRIORITY_HIGH_PLUS3,
54+
THREAD_PRIORITY_HIGHEST_MINUS3,
55+
THREAD_PRIORITY_HIGHEST_MINUS2,
56+
THREAD_PRIORITY_HIGHEST_MINUS1,
57+
THREAD_PRIORITY_HIGHEST
5258
};
5359

5460
/// Calculates an OS specific thread priority from a ThreadPriority value.
@@ -58,7 +64,7 @@ enum ThreadPriority
5864
* \return RCUTILS_RET_OK on systems that support POSIX
5965
*/
6066
RCUTILS_LOCAL
61-
rcutils_ret_t calculate_os_thread_priority(
67+
rcutils_ret_t calculate_os_fifo_thread_priority(
6268
const int thread_priority,
6369
int * os_priority);
6470

src/thread.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extern "C"
3737
{
3838
#endif
3939

40-
rcutils_ret_t calculate_os_thread_priority(
40+
rcutils_ret_t calculate_os_fifo_thread_priority(
4141
const int thread_priority,
4242
int * os_priority)
4343
{
@@ -46,15 +46,15 @@ rcutils_ret_t calculate_os_thread_priority(
4646
#elif __APPLE__
4747
return RCUTILS_RET_ERROR;
4848
#else
49-
if (thread_priority > THREAD_PRIORITY_HIGH || thread_priority < THREAD_PRIORITY_LOW) {
49+
if (thread_priority > THREAD_PRIORITY_HIGHEST || thread_priority < THREAD_PRIORITY_LOWEST) {
5050
return RCUTILS_RET_ERROR;
5151
}
5252
const int max_prio = sched_get_priority_max(SCHED_FIFO);
5353
const int min_prio = sched_get_priority_min(SCHED_FIFO);
5454
const int range_prio = max_prio - min_prio;
5555

56-
int priority = min_prio + (thread_priority - THREAD_PRIORITY_LOW) *
57-
range_prio / (THREAD_PRIORITY_HIGH - THREAD_PRIORITY_LOW);
56+
int priority = min_prio + (thread_priority - THREAD_PRIORITY_LOWEST) *
57+
range_prio / (THREAD_PRIORITY_HIGHEST - THREAD_PRIORITY_LOWEST);
5858
if (priority > min_prio && priority < max_prio) {
5959
// on Linux systems THREAD_PRIORITY_MEDIUM should be prio 49 instead of 50
6060
// in order to not block any interrupt handlers
@@ -80,7 +80,7 @@ rcutils_ret_t configure_native_realtime_thread(
8080
struct sched_param params;
8181
int policy;
8282
success &= (pthread_getschedparam(native_handle, &policy, &params) == 0);
83-
success &= (calculate_os_thread_priority(priority, &params.sched_priority) ==
83+
success &= (calculate_os_fifo_thread_priority(priority, &params.sched_priority) ==
8484
RCUTILS_RET_OK ? 1 : 0);
8585
success &= (pthread_setschedparam(native_handle, SCHED_FIFO, &params) == 0);
8686

0 commit comments

Comments
 (0)