diff options
Diffstat (limited to 'src/threading.cpp')
-rw-r--r-- | src/threading.cpp | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/src/threading.cpp b/src/threading.cpp index 2464d03..4f3cbc8 100644 --- a/src/threading.cpp +++ b/src/threading.cpp | |||
@@ -68,7 +68,7 @@ THE SOFTWARE. | |||
68 | /* Linux needs to check, whether it's been run as root | 68 | /* Linux needs to check, whether it's been run as root |
69 | */ | 69 | */ |
70 | #ifdef PLATFORM_LINUX | 70 | #ifdef PLATFORM_LINUX |
71 | volatile bool_t sudo; | 71 | volatile bool sudo; |
72 | #endif | 72 | #endif |
73 | 73 | ||
74 | #ifdef PLATFORM_OSX | 74 | #ifdef PLATFORM_OSX |
@@ -271,12 +271,12 @@ static void prepare_timeout( struct timespec *ts, time_d abs_secs ) { | |||
271 | #if _WIN32_WINNT < 0x0600 // CONDITION_VARIABLE aren't available | 271 | #if _WIN32_WINNT < 0x0600 // CONDITION_VARIABLE aren't available |
272 | // | 272 | // |
273 | void MUTEX_INIT( MUTEX_T *ref ) { | 273 | void MUTEX_INIT( MUTEX_T *ref ) { |
274 | *ref= CreateMutex( NULL /*security attr*/, FALSE /*not locked*/, NULL ); | 274 | *ref= CreateMutex( nullptr /*security attr*/, false /*not locked*/, nullptr ); |
275 | if (!ref) FAIL( "CreateMutex", GetLastError() ); | 275 | if (!ref) FAIL( "CreateMutex", GetLastError() ); |
276 | } | 276 | } |
277 | void MUTEX_FREE( MUTEX_T *ref ) { | 277 | void MUTEX_FREE( MUTEX_T *ref ) { |
278 | if (!CloseHandle(*ref)) FAIL( "CloseHandle (mutex)", GetLastError() ); | 278 | if (!CloseHandle(*ref)) FAIL( "CloseHandle (mutex)", GetLastError() ); |
279 | *ref= NULL; | 279 | *ref= nullptr; |
280 | } | 280 | } |
281 | void MUTEX_LOCK( MUTEX_T *ref ) | 281 | void MUTEX_LOCK( MUTEX_T *ref ) |
282 | { | 282 | { |
@@ -352,7 +352,7 @@ void THREAD_SET_AFFINITY( unsigned int aff) | |||
352 | } | 352 | } |
353 | } | 353 | } |
354 | 354 | ||
355 | bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | 355 | bool THREAD_WAIT_IMPL( THREAD_T *ref, double secs) |
356 | { | 356 | { |
357 | DWORD ms = (secs<0.0) ? INFINITE : (DWORD)((secs*1000.0)+0.5); | 357 | DWORD ms = (secs<0.0) ? INFINITE : (DWORD)((secs*1000.0)+0.5); |
358 | 358 | ||
@@ -363,10 +363,10 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
363 | // WAIT_TIMEOUT | 363 | // WAIT_TIMEOUT |
364 | // WAIT_FAILED more info via GetLastError() | 364 | // WAIT_FAILED more info via GetLastError() |
365 | 365 | ||
366 | if (rc == WAIT_TIMEOUT) return FALSE; | 366 | if (rc == WAIT_TIMEOUT) return false; |
367 | if( rc !=0) FAIL( "WaitForSingleObject", rc==WAIT_FAILED ? GetLastError() : rc); | 367 | if( rc !=0) FAIL( "WaitForSingleObject", rc==WAIT_FAILED ? GetLastError() : rc); |
368 | *ref= NULL; // thread no longer usable | 368 | *ref= NULL; // thread no longer usable |
369 | return TRUE; | 369 | return true; |
370 | } | 370 | } |
371 | // | 371 | // |
372 | void THREAD_KILL( THREAD_T *ref ) | 372 | void THREAD_KILL( THREAD_T *ref ) |
@@ -420,9 +420,9 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
420 | { | 420 | { |
421 | InitializeCriticalSection( &ref->signalCS); | 421 | InitializeCriticalSection( &ref->signalCS); |
422 | InitializeCriticalSection( &ref->countCS); | 422 | InitializeCriticalSection( &ref->countCS); |
423 | if( 0 == (ref->waitEvent = CreateEvent( 0, TRUE, FALSE, 0))) // manual-reset | 423 | if( 0 == (ref->waitEvent = CreateEvent( 0, true, false, 0))) // manual-reset |
424 | FAIL( "CreateEvent", GetLastError()); | 424 | FAIL( "CreateEvent", GetLastError()); |
425 | if( 0 == (ref->waitDoneEvent = CreateEvent( 0, FALSE, FALSE, 0))) // auto-reset | 425 | if( 0 == (ref->waitDoneEvent = CreateEvent( 0, false, false, 0))) // auto-reset |
426 | FAIL( "CreateEvent", GetLastError()); | 426 | FAIL( "CreateEvent", GetLastError()); |
427 | ref->waitersCount = 0; | 427 | ref->waitersCount = 0; |
428 | } | 428 | } |
@@ -435,7 +435,7 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
435 | DeleteCriticalSection( &ref->signalCS); | 435 | DeleteCriticalSection( &ref->signalCS); |
436 | } | 436 | } |
437 | 437 | ||
438 | bool_t SIGNAL_WAIT( SIGNAL_T* ref, MUTEX_T* mu_ref, time_d abs_secs) | 438 | bool SIGNAL_WAIT( SIGNAL_T* ref, MUTEX_T* mu_ref, time_d abs_secs) |
439 | { | 439 | { |
440 | DWORD errc; | 440 | DWORD errc; |
441 | DWORD ms; | 441 | DWORD ms; |
@@ -458,7 +458,7 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
458 | LeaveCriticalSection( &ref->countCS); | 458 | LeaveCriticalSection( &ref->countCS); |
459 | LeaveCriticalSection( &ref->signalCS); | 459 | LeaveCriticalSection( &ref->signalCS); |
460 | 460 | ||
461 | errc = SignalObjectAndWait( *mu_ref, ref->waitEvent, ms, FALSE); | 461 | errc = SignalObjectAndWait( *mu_ref, ref->waitEvent, ms, false); |
462 | 462 | ||
463 | EnterCriticalSection( &ref->countCS); | 463 | EnterCriticalSection( &ref->countCS); |
464 | if( 0 == -- ref->waitersCount) | 464 | if( 0 == -- ref->waitersCount) |
@@ -473,13 +473,13 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
473 | switch( errc) | 473 | switch( errc) |
474 | { | 474 | { |
475 | case WAIT_TIMEOUT: | 475 | case WAIT_TIMEOUT: |
476 | return FALSE; | 476 | return false; |
477 | case WAIT_OBJECT_0: | 477 | case WAIT_OBJECT_0: |
478 | return TRUE; | 478 | return true; |
479 | } | 479 | } |
480 | 480 | ||
481 | FAIL( "SignalObjectAndWait", GetLastError()); | 481 | FAIL( "SignalObjectAndWait", GetLastError()); |
482 | return FALSE; | 482 | return false; |
483 | } | 483 | } |
484 | 484 | ||
485 | void SIGNAL_ALL( SIGNAL_T* ref) | 485 | void SIGNAL_ALL( SIGNAL_T* ref) |
@@ -521,7 +521,7 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
521 | (void)ref; | 521 | (void)ref; |
522 | } | 522 | } |
523 | 523 | ||
524 | bool_t SIGNAL_WAIT( SIGNAL_T *ref, MUTEX_T *mu_ref, time_d abs_secs) | 524 | bool SIGNAL_WAIT( SIGNAL_T *ref, MUTEX_T *mu_ref, time_d abs_secs) |
525 | { | 525 | { |
526 | long ms; | 526 | long ms; |
527 | 527 | ||
@@ -544,14 +544,14 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
544 | { | 544 | { |
545 | if( GetLastError() == ERROR_TIMEOUT) | 545 | if( GetLastError() == ERROR_TIMEOUT) |
546 | { | 546 | { |
547 | return FALSE; | 547 | return false; |
548 | } | 548 | } |
549 | else | 549 | else |
550 | { | 550 | { |
551 | FAIL( "SleepConditionVariableCS", GetLastError()); | 551 | FAIL( "SleepConditionVariableCS", GetLastError()); |
552 | } | 552 | } |
553 | } | 553 | } |
554 | return TRUE; | 554 | return true; |
555 | } | 555 | } |
556 | 556 | ||
557 | void SIGNAL_ONE( SIGNAL_T *ref ) | 557 | void SIGNAL_ONE( SIGNAL_T *ref ) |
@@ -620,7 +620,7 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
620 | * a timed out sleep. A Linda with some other key read, or just because | 620 | * a timed out sleep. A Linda with some other key read, or just because |
621 | * PThread cond vars can wake up unwantedly. | 621 | * PThread cond vars can wake up unwantedly. |
622 | */ | 622 | */ |
623 | bool_t SIGNAL_WAIT( SIGNAL_T *ref, pthread_mutex_t *mu, time_d abs_secs ) { | 623 | bool SIGNAL_WAIT( SIGNAL_T *ref, pthread_mutex_t *mu, time_d abs_secs ) { |
624 | if (abs_secs<0.0) { | 624 | if (abs_secs<0.0) { |
625 | PT_CALL( pthread_cond_wait( ref, mu ) ); // infinite | 625 | PT_CALL( pthread_cond_wait( ref, mu ) ); // infinite |
626 | } else { | 626 | } else { |
@@ -632,10 +632,10 @@ bool_t THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
632 | 632 | ||
633 | rc= pthread_cond_timedwait( ref, mu, &ts ); | 633 | rc= pthread_cond_timedwait( ref, mu, &ts ); |
634 | 634 | ||
635 | if (rc==ETIMEDOUT) return FALSE; | 635 | if (rc==ETIMEDOUT) return false; |
636 | if (rc) { _PT_FAIL( rc, "pthread_cond_timedwait()", __FILE__, __LINE__ ); } | 636 | if (rc) { _PT_FAIL( rc, "pthread_cond_timedwait()", __FILE__, __LINE__ ); } |
637 | } | 637 | } |
638 | return TRUE; | 638 | return true; |
639 | } | 639 | } |
640 | // | 640 | // |
641 | void SIGNAL_ONE( SIGNAL_T *ref ) { | 641 | void SIGNAL_ONE( SIGNAL_T *ref ) { |
@@ -778,7 +778,7 @@ static int select_prio(int prio /* -3..+3 */) | |||
778 | void THREAD_CREATE( THREAD_T* ref, THREAD_RETURN_T (*func)( void*), void* data, int prio /* -3..+3 */) | 778 | void THREAD_CREATE( THREAD_T* ref, THREAD_RETURN_T (*func)( void*), void* data, int prio /* -3..+3 */) |
779 | { | 779 | { |
780 | pthread_attr_t a; | 780 | pthread_attr_t a; |
781 | bool_t const change_priority = | 781 | bool const change_priority = |
782 | #ifdef PLATFORM_LINUX | 782 | #ifdef PLATFORM_LINUX |
783 | sudo && // only root-privileged process can change priorities | 783 | sudo && // only root-privileged process can change priorities |
784 | #endif | 784 | #endif |
@@ -935,13 +935,13 @@ void THREAD_SET_AFFINITY( unsigned int aff) | |||
935 | * 'mu_ref' is a lock we should use for the waiting; initially unlocked. | 935 | * 'mu_ref' is a lock we should use for the waiting; initially unlocked. |
936 | * Same lock as passed to THREAD_EXIT. | 936 | * Same lock as passed to THREAD_EXIT. |
937 | * | 937 | * |
938 | * Returns TRUE for successful wait, FALSE for timed out | 938 | * Returns true for successful wait, false for timed out |
939 | */ | 939 | */ |
940 | bool_t THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T *mu_ref, volatile enum e_status *st_ref) | 940 | bool THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T *mu_ref, volatile enum e_status *st_ref) |
941 | { | 941 | { |
942 | struct timespec ts_store; | 942 | struct timespec ts_store; |
943 | const struct timespec *timeout= NULL; | 943 | const struct timespec *timeout= NULL; |
944 | bool_t done; | 944 | bool done; |
945 | 945 | ||
946 | // Do timeout counting before the locks | 946 | // Do timeout counting before the locks |
947 | // | 947 | // |
@@ -960,7 +960,7 @@ bool_t THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T * | |||
960 | */ | 960 | */ |
961 | if (!timeout) { | 961 | if (!timeout) { |
962 | PT_CALL( pthread_join( *ref, NULL /*ignore exit value*/ )); | 962 | PT_CALL( pthread_join( *ref, NULL /*ignore exit value*/ )); |
963 | done= TRUE; | 963 | done = true; |
964 | } else { | 964 | } else { |
965 | int rc= PTHREAD_TIMEDJOIN( *ref, NULL, timeout ); | 965 | int rc= PTHREAD_TIMEDJOIN( *ref, NULL, timeout ); |
966 | if ((rc!=0) && (rc!=ETIMEDOUT)) { | 966 | if ((rc!=0) && (rc!=ETIMEDOUT)) { |