|
1 | | -// Copyright 2019 Open Source Robotics Foundation, Inc. |
| 1 | +// Copyright 2023 Open Source Robotics Foundation, Inc. |
2 | 2 | // |
3 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | 4 | // you may not use this file except in compliance with the License. |
|
19 | 19 |
|
20 | 20 | #include "rcpputils/mutex.hpp" |
21 | 21 |
|
22 | | -#ifdef __linux__ |
| 22 | +#ifdef RCPPUTILS_USE_PIMUTEX |
23 | 23 | #include <pthread.h> |
24 | 24 | #include "rcutils/types/rcutils_ret.h" |
25 | | -#endif // __linux__ |
| 25 | +#ifdef __QNXNTO__ |
| 26 | + #include <sys/neutrino.h> |
| 27 | + #include <sys/syspage.h> |
| 28 | +#endif // __QNXNTO__ |
| 29 | +#endif // RCPPUTILS_USE_PIMUTEX |
26 | 30 |
|
27 | 31 | using namespace std::chrono_literals; |
28 | 32 |
|
@@ -99,7 +103,7 @@ TEST(test_mutex, pimutex_lockthread) { |
99 | 103 | test_thread.join(); |
100 | 104 | } |
101 | 105 |
|
102 | | -#ifdef __linux__ |
| 106 | +#ifdef RCPPUTILS_USE_PIMUTEX |
103 | 107 | // |
104 | 108 | // The test cases pimutex_priority_inversion & rpimutex_priority_inversion provoke |
105 | 109 | // a thread priority inversion. To do so they need to configure the cpu priority, |
@@ -160,14 +164,27 @@ rcutils_ret_t configure_native_realtime_thread( |
160 | 164 | RCUTILS_RET_OK ? 1 : 0); |
161 | 165 | success &= (pthread_setschedparam(native_handle, SCHED_FIFO, ¶ms) == 0); |
162 | 166 |
|
| 167 | +#ifdef __QNXNTO__ |
| 168 | + // run_mask is a bit mask to set which cpu a thread runs on |
| 169 | + // where each bit corresponds to a cpu core |
| 170 | + int64_t run_mask = cpu_bitmask; |
| 171 | + |
| 172 | + // change thread affinity of thread associated with native_handle |
| 173 | + success &= (ThreadCtlExt( |
| 174 | + 0, native_handle, _NTO_TCTL_RUNMASK, |
| 175 | + reinterpret_cast<void *>(run_mask)) != -1); |
| 176 | +#else // __QNXNTO__ |
163 | 177 | cpu_set_t cpuset; |
164 | 178 | CPU_ZERO(&cpuset); |
165 | 179 | for (unsigned int i = 0; i < sizeof(cpu_bitmask) * 8; i++) { |
166 | 180 | if ( (cpu_bitmask & (1 << i)) != 0) { |
167 | 181 | CPU_SET(i, &cpuset); |
168 | 182 | } |
169 | 183 | } |
| 184 | + |
| 185 | + // change thread affinity of thread associated with native_handle |
170 | 186 | success &= (pthread_setaffinity_np(native_handle, sizeof(cpu_set_t), &cpuset) == 0); |
| 187 | +#endif // __QNXNTO__ |
171 | 188 |
|
172 | 189 | return success ? RCUTILS_RET_OK : RCUTILS_RET_ERROR; |
173 | 190 | } |
@@ -285,4 +302,4 @@ TEST(test_mutex, rpimutex_priority_inversion) { |
285 | 302 | priority_inheritance_test<rcpputils::RecursivePIMutex>(); |
286 | 303 | } |
287 | 304 |
|
288 | | -#endif // __linux__ |
| 305 | +#endif // RCPPUTILS_USE_PIMUTEX |
0 commit comments