aboutsummaryrefslogtreecommitdiff
path: root/src/threading.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/threading.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/threading.c b/src/threading.c
index 0a4c62a..c0e6a55 100644
--- a/src/threading.c
+++ b/src/threading.c
@@ -324,6 +324,13 @@ void THREAD_SET_PRIORITY( int prio)
324 } 324 }
325} 325}
326 326
327void THREAD_SET_AFFINITY( unsigned int aff)
328{
329 if( !SetThreadAffinityMask( GetCurrentThread(), aff));
330 {
331 FAIL( "THREAD_SET_AFFINITY", GetLastError());
332 }
333}
327 334
328bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) 335bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs)
329{ 336{
@@ -546,6 +553,7 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs)
546 // On Linux, SCHED_RR and su privileges are required.. !-( 553 // On Linux, SCHED_RR and su privileges are required.. !-(
547 // 554 //
548 #include <errno.h> 555 #include <errno.h>
556 #include <sched.h>
549 557
550# if (defined(__MINGW32__) || defined(__MINGW64__)) && defined pthread_attr_setschedpolicy 558# if (defined(__MINGW32__) || defined(__MINGW64__)) && defined pthread_attr_setschedpolicy
551# if pthread_attr_setschedpolicy( A, S) == ENOTSUP 559# if pthread_attr_setschedpolicy( A, S) == ENOTSUP
@@ -862,6 +870,22 @@ void THREAD_SET_PRIORITY( int prio)
862 } 870 }
863} 871}
864 872
873void THREAD_SET_AFFINITY( unsigned int aff)
874{
875 cpu_set_t cpuset;
876 int bit = 0;
877 CPU_ZERO( &cpuset);
878 while( aff != 0)
879 {
880 if( aff & 1)
881 {
882 CPU_SET( bit, &cpuset);
883 }
884 ++ bit;
885 aff >>= 1;
886 }
887 PT_CALL( pthread_setaffinity_np( pthread_self(), sizeof(cpu_set_t), &cpuset));
888}
865 889
866 /* 890 /*
867 * Wait for a thread to finish. 891 * Wait for a thread to finish.
@@ -959,7 +983,7 @@ bool_t THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T *
959#elif defined PLATFORM_OSX 983#elif defined PLATFORM_OSX
960 pthread_setname_np(_name); 984 pthread_setname_np(_name);
961#elif defined PLATFORM_WIN32 || defined PLATFORM_POCKETPC 985#elif defined PLATFORM_WIN32 || defined PLATFORM_POCKETPC
962 // no API in win32-pthread yet :-( 986 PT_CALL( pthread_setname_np( pthread_self(), _name));
963#endif 987#endif
964 } 988 }
965#endif // THREADAPI == THREADAPI_PTHREAD 989#endif // THREADAPI == THREADAPI_PTHREAD