diff options
Diffstat (limited to 'src/threading.cpp')
-rw-r--r-- | src/threading.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/threading.cpp b/src/threading.cpp index bedbcf8..3e594ff 100644 --- a/src/threading.cpp +++ b/src/threading.cpp | |||
@@ -86,7 +86,7 @@ THE SOFTWARE. | |||
86 | * FAIL is for unexpected API return values - essentially programming | 86 | * FAIL is for unexpected API return values - essentially programming |
87 | * error in _this_ code. | 87 | * error in _this_ code. |
88 | */ | 88 | */ |
89 | #if defined(PLATFORM_XBOX) || defined(PLATFORM_WIN32) || defined(PLATFORM_POCKETPC) | 89 | #if HAVE_WIN32 |
90 | static void FAIL(char const* funcname_, DWORD const rc_) | 90 | static void FAIL(char const* funcname_, DWORD const rc_) |
91 | { | 91 | { |
92 | #if defined(PLATFORM_XBOX) | 92 | #if defined(PLATFORM_XBOX) |
@@ -101,7 +101,7 @@ static void FAIL(char const* funcname_, DWORD const rc_) | |||
101 | #endif // _MSC_VER | 101 | #endif // _MSC_VER |
102 | abort(); | 102 | abort(); |
103 | } | 103 | } |
104 | #endif // win32 build | 104 | #endif // HAVE_WIN32 |
105 | 105 | ||
106 | /*---=== Threading ===---*/ | 106 | /*---=== Threading ===---*/ |
107 | 107 | ||
@@ -136,7 +136,7 @@ void THREAD_SET_PRIORITY(std::thread& thread_, int prio_, [[maybe_unused]] bool | |||
136 | // prio range [-3,+3] was checked by the caller | 136 | // prio range [-3,+3] was checked by the caller |
137 | // for some reason when building for mingw, native_handle() is an unsigned long long, but HANDLE is a void* | 137 | // for some reason when building for mingw, native_handle() is an unsigned long long, but HANDLE is a void* |
138 | // -> need a strong cast to make g++ happy | 138 | // -> need a strong cast to make g++ happy |
139 | if (!SetThreadPriority((HANDLE)thread_.native_handle(), gs_prio_remap[prio_ + 3])) { | 139 | if (!SetThreadPriority(thread_.native_handle(), gs_prio_remap[prio_ + 3])) { |
140 | FAIL("THREAD_SET_PRIORITY", GetLastError()); | 140 | FAIL("THREAD_SET_PRIORITY", GetLastError()); |
141 | } | 141 | } |
142 | } | 142 | } |
@@ -382,7 +382,7 @@ void THREAD_SET_PRIORITY(std::thread& thread_, int prio_, [[maybe_unused]] bool | |||
382 | struct sched_param sp; | 382 | struct sched_param sp; |
383 | // prio range [-3,+3] was checked by the caller | 383 | // prio range [-3,+3] was checked by the caller |
384 | sp.sched_priority = gs_prio_remap[prio_ + 3]; | 384 | sp.sched_priority = gs_prio_remap[prio_ + 3]; |
385 | PT_CALL(pthread_setschedparam(static_cast<pthread_t>(thread_.native_handle()), _PRIO_MODE, &sp)); | 385 | PT_CALL(pthread_setschedparam(thread_.native_handle(), _PRIO_MODE, &sp)); |
386 | } | 386 | } |
387 | 387 | ||
388 | // ################################################################################################# | 388 | // ################################################################################################# |
@@ -398,6 +398,12 @@ void THREAD_SET_AFFINITY(unsigned int aff_) | |||
398 | 398 | ||
399 | void THREAD_SET_AFFINITY(unsigned int aff_) | 399 | void THREAD_SET_AFFINITY(unsigned int aff_) |
400 | { | 400 | { |
401 | #if HAVE_WIN32 // "hybrid": Win32 API is available, and pthread too | ||
402 | // since pthread_setaffinity_np can be missing (for example mingw), use win32 api instead | ||
403 | if (!SetThreadAffinityMask(GetCurrentThread(), aff_)) { | ||
404 | FAIL("THREAD_SET_AFFINITY", GetLastError()); | ||
405 | } | ||
406 | #else // pure pthread | ||
401 | int bit = 0; | 407 | int bit = 0; |
402 | #ifdef __NetBSD__ | 408 | #ifdef __NetBSD__ |
403 | cpuset_t* cpuset = cpuset_create(); | 409 | cpuset_t* cpuset = cpuset_create(); |
@@ -423,6 +429,7 @@ void THREAD_SET_AFFINITY(unsigned int aff_) | |||
423 | #else | 429 | #else |
424 | PT_CALL(pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset)); | 430 | PT_CALL(pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset)); |
425 | #endif | 431 | #endif |
432 | #endif // PLATFORM_MINGW | ||
426 | } | 433 | } |
427 | 434 | ||
428 | #endif // __PROSPERO__ | 435 | #endif // __PROSPERO__ |