Skip to content

Commit 44c4c48

Browse files
committed
modified return type
1 parent 4d7639b commit 44c4c48

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

include/rcutils/thread.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define RCUTILS__THREAD_H_
1717

1818
#include "rcutils/visibility_control.h"
19+
#include "rcutils/types/rcutils_ret.h"
1920

2021
#ifdef __cplusplus
2122
extern "C"
@@ -34,10 +35,10 @@ enum ThreadPriority
3435
/**
3536
* \param[in] thread_priority thread priority of type ThreadPriority
3637
* \param[out] os_priority OS specific thread priority
37-
* \return 1 on systems that support POSIX, else 0
38+
* \return RCUTILS_RET_OK on systems that support POSIX
3839
*/
3940
RCUTILS_LOCAL
40-
int calculate_os_thread_priority(
41+
rcutils_ret_t calculate_os_thread_priority(
4142
const int thread_priority,
4243
int * os_priority);
4344

@@ -52,10 +53,10 @@ int calculate_os_thread_priority(
5253
* \param[in] native_handle native thread handle
5354
* \param[in] priority priority of type ThreadPriority to be set for the given thread
5455
* \param[in] cpu_bitmask cpu core bitmask for the given thread; use (unsigned) -1 for all cores
55-
* \return 1 on success, 0 on error
56+
* \return RCUTILS_RET_OK on success
5657
*/
5758
RCUTILS_PUBLIC
58-
int configure_native_realtime_thread(
59+
rcutils_ret_t configure_native_realtime_thread(
5960
unsigned long int native_handle, const int priority,
6061
const unsigned int cpu_bitmask);
6162

src/thread.c

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

40-
int calculate_os_thread_priority(
40+
rcutils_ret_t calculate_os_thread_priority(
4141
const int thread_priority,
4242
int * os_priority)
4343
{
4444
#ifdef _WIN32
45-
return false;
45+
return RCUTILS_RET_ERROR;
4646
#elif __APPLE__
47-
return false;
47+
return RCUTILS_RET_ERROR;
4848
#else
4949
if (thread_priority == THREAD_PRIORITY_HIGH) {
5050
*os_priority = sched_get_priority_max(SCHED_FIFO);
@@ -56,26 +56,27 @@ int calculate_os_thread_priority(
5656
*os_priority =
5757
(sched_get_priority_min(SCHED_FIFO) + sched_get_priority_max(SCHED_FIFO)) / 2 - 1;
5858
} else { // unhandled priority
59-
return 0;
59+
return RCUTILS_RET_ERROR;
6060
}
61-
return 1;
61+
return RCUTILS_RET_OK;
6262
#endif
6363
}
6464

65-
int configure_native_realtime_thread(
65+
rcutils_ret_t configure_native_realtime_thread(
6666
unsigned long int native_handle, const int priority,
6767
const unsigned int cpu_bitmask)
6868
{
6969
int success = 1;
7070
#ifdef _WIN32
71-
return false;
71+
return RCUTILS_RET_ERROR;
7272
#elif __APPLE__
73-
return false;
73+
return RCUTILS_RET_ERROR;
7474
#else // POSIX systems
7575
struct sched_param params;
7676
int policy;
7777
success &= (pthread_getschedparam(native_handle, &policy, &params) == 0);
78-
success &= calculate_os_thread_priority(priority, &params.sched_priority);
78+
success &= (calculate_os_thread_priority(priority, &params.sched_priority) ==
79+
RCUTILS_RET_OK ? 1 : 0);
7980
success &= (pthread_setschedparam(native_handle, SCHED_FIFO, &params) == 0);
8081

8182
#ifdef __QNXNTO__
@@ -104,7 +105,7 @@ int configure_native_realtime_thread(
104105
#endif // __QNXNTO__
105106
#endif
106107

107-
return success;
108+
return success ? RCUTILS_RET_OK : RCUTILS_RET_ERROR;
108109
}
109110

110111
#ifdef __cplusplus

0 commit comments

Comments
 (0)