diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-09 10:12:30 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-04-09 10:12:30 +0200 |
commit | 23f25f3a9d327153e4c16ca86d937ec334803a10 (patch) | |
tree | 110826adcf29554cd59768acdccf3de006e8a7f4 /src/threading.cpp | |
parent | 9b5c27af793a08fd17d1fde93e9512e76536f484 (diff) | |
download | lanes-23f25f3a9d327153e4c16ca86d937ec334803a10.tar.gz lanes-23f25f3a9d327153e4c16ca86d937ec334803a10.tar.bz2 lanes-23f25f3a9d327153e4c16ca86d937ec334803a10.zip |
C++ migration: still more threading code cleanup. 'sudo' global moved in the Universe
Diffstat (limited to 'src/threading.cpp')
-rw-r--r-- | src/threading.cpp | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/threading.cpp b/src/threading.cpp index aab2fa7..4d210d6 100644 --- a/src/threading.cpp +++ b/src/threading.cpp | |||
@@ -65,12 +65,6 @@ THE SOFTWARE. | |||
65 | # include <unistd.h> | 65 | # include <unistd.h> |
66 | #endif | 66 | #endif |
67 | 67 | ||
68 | /* Linux needs to check, whether it's been run as root | ||
69 | */ | ||
70 | #ifdef PLATFORM_LINUX | ||
71 | volatile bool sudo; | ||
72 | #endif | ||
73 | |||
74 | #ifdef PLATFORM_OSX | 68 | #ifdef PLATFORM_OSX |
75 | # include "threading_osx.h" | 69 | # include "threading_osx.h" |
76 | #endif | 70 | #endif |
@@ -134,10 +128,10 @@ static int const gs_prio_remap[] = | |||
134 | 128 | ||
135 | // ############################################################################################### | 129 | // ############################################################################################### |
136 | 130 | ||
137 | void THREAD_SET_PRIORITY(int prio) | 131 | void THREAD_SET_PRIORITY(int prio_, [[maybe_unused]] bool sudo_) |
138 | { | 132 | { |
139 | // prio range [-3,+3] was checked by the caller | 133 | // prio range [-3,+3] was checked by the caller |
140 | if (!SetThreadPriority(GetCurrentThread(), gs_prio_remap[prio + 3])) | 134 | if (!SetThreadPriority(GetCurrentThread(), gs_prio_remap[prio_ + 3])) |
141 | { | 135 | { |
142 | FAIL("THREAD_SET_PRIORITY", GetLastError()); | 136 | FAIL("THREAD_SET_PRIORITY", GetLastError()); |
143 | } | 137 | } |
@@ -145,7 +139,7 @@ void THREAD_SET_PRIORITY(int prio) | |||
145 | 139 | ||
146 | // ############################################################################################### | 140 | // ############################################################################################### |
147 | 141 | ||
148 | void JTHREAD_SET_PRIORITY(std::jthread& thread_, int prio_) | 142 | void JTHREAD_SET_PRIORITY(std::jthread& thread_, int prio_, [[maybe_unused]] bool sudo_) |
149 | { | 143 | { |
150 | // prio range [-3,+3] was checked by the caller | 144 | // prio range [-3,+3] was checked by the caller |
151 | if (!SetThreadPriority(thread_.native_handle(), gs_prio_remap[prio_ + 3])) | 145 | if (!SetThreadPriority(thread_.native_handle(), gs_prio_remap[prio_ + 3])) |
@@ -368,25 +362,25 @@ static int select_prio(int prio /* -3..+3 */) | |||
368 | return gs_prio_remap[prio + 3]; | 362 | return gs_prio_remap[prio + 3]; |
369 | } | 363 | } |
370 | 364 | ||
371 | void THREAD_SET_PRIORITY(int prio) | 365 | void THREAD_SET_PRIORITY(int prio_, [[maybe_unused]] bool sudo_) |
372 | { | 366 | { |
373 | #ifdef PLATFORM_LINUX | 367 | #ifdef PLATFORM_LINUX |
374 | if (!sudo) // only root-privileged process can change priorities | 368 | if (!sudo_) // only root-privileged process can change priorities |
375 | return; | 369 | return; |
376 | #endif // PLATFORM_LINUX | 370 | #endif // PLATFORM_LINUX |
377 | 371 | ||
378 | struct sched_param sp; | 372 | struct sched_param sp; |
379 | // prio range [-3,+3] was checked by the caller | 373 | // prio range [-3,+3] was checked by the caller |
380 | sp.sched_priority = gs_prio_remap[prio + 3]; | 374 | sp.sched_priority = gs_prio_remap[prio_ + 3]; |
381 | PT_CALL(pthread_setschedparam(pthread_self(), _PRIO_MODE, &sp)); | 375 | PT_CALL(pthread_setschedparam(pthread_self(), _PRIO_MODE, &sp)); |
382 | } | 376 | } |
383 | 377 | ||
384 | // ################################################################################################# | 378 | // ################################################################################################# |
385 | 379 | ||
386 | void JTHREAD_SET_PRIORITY(std::jthread& thread_, int prio_) | 380 | void JTHREAD_SET_PRIORITY(std::jthread& thread_, int prio_, [[maybe_unused]] bool sudo_) |
387 | { | 381 | { |
388 | #ifdef PLATFORM_LINUX | 382 | #ifdef PLATFORM_LINUX |
389 | if (!sudo) // only root-privileged process can change priorities | 383 | if (!sudo_) // only root-privileged process can change priorities |
390 | return; | 384 | return; |
391 | #endif // PLATFORM_LINUX | 385 | #endif // PLATFORM_LINUX |
392 | 386 | ||