diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-03-20 16:53:14 +0100 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-03-20 16:53:14 +0100 |
| commit | df1113151aff47bfd1b401bf8d06a3fe8f6b9115 (patch) | |
| tree | e14449dad963d0b441edebf2cf74713d5b9dd665 /src/threading.cpp | |
| parent | 6556cc558f0602cc99b1a8d1c7212b2e91490cdc (diff) | |
| download | lanes-df1113151aff47bfd1b401bf8d06a3fe8f6b9115.tar.gz lanes-df1113151aff47bfd1b401bf8d06a3fe8f6b9115.tar.bz2 lanes-df1113151aff47bfd1b401bf8d06a3fe8f6b9115.zip | |
C++ migration: more NULL → nullptr
Diffstat (limited to 'src/threading.cpp')
| -rw-r--r-- | src/threading.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/threading.cpp b/src/threading.cpp index 4f3cbc8..636fe91 100644 --- a/src/threading.cpp +++ b/src/threading.cpp | |||
| @@ -107,7 +107,7 @@ static void FAIL( char const* funcname, int rc) | |||
| 107 | fprintf( stderr, "%s() failed! (%d)\n", funcname, rc ); | 107 | fprintf( stderr, "%s() failed! (%d)\n", funcname, rc ); |
| 108 | #else // PLATFORM_XBOX | 108 | #else // PLATFORM_XBOX |
| 109 | char buf[256]; | 109 | char buf[256]; |
| 110 | FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM, NULL, rc, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 256, NULL); | 110 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, rc, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 256, nullptr); |
| 111 | fprintf( stderr, "%s() failed! [GetLastError() -> %d] '%s'", funcname, rc, buf); | 111 | fprintf( stderr, "%s() failed! [GetLastError() -> %d] '%s'", funcname, rc, buf); |
| 112 | #endif // PLATFORM_XBOX | 112 | #endif // PLATFORM_XBOX |
| 113 | #ifdef _MSC_VER | 113 | #ifdef _MSC_VER |
| @@ -188,7 +188,7 @@ time_d now_secs(void) { | |||
| 188 | // suseconds_t tv_usec; /* and microseconds */ | 188 | // suseconds_t tv_usec; /* and microseconds */ |
| 189 | // }; | 189 | // }; |
| 190 | 190 | ||
| 191 | int rc= gettimeofday( &tv, NULL /*time zone not used any more (in Linux)*/ ); | 191 | int rc = gettimeofday(&tv, nullptr /*time zone not used any more (in Linux)*/); |
| 192 | assert( rc==0 ); | 192 | assert( rc==0 ); |
| 193 | 193 | ||
| 194 | return ((double)tv.tv_sec) + ((tv.tv_usec)/1000) / 1000.0; | 194 | return ((double)tv.tv_sec) + ((tv.tv_usec)/1000) / 1000.0; |
| @@ -310,15 +310,15 @@ MSDN: "you can create at most 2028 threads" | |||
| 310 | // Note: Visual C++ requires '__stdcall' where it is | 310 | // Note: Visual C++ requires '__stdcall' where it is |
| 311 | void THREAD_CREATE( THREAD_T* ref, THREAD_RETURN_T (__stdcall *func)( void*), void* data, int prio /* -3..+3 */) | 311 | void THREAD_CREATE( THREAD_T* ref, THREAD_RETURN_T (__stdcall *func)( void*), void* data, int prio /* -3..+3 */) |
| 312 | { | 312 | { |
| 313 | HANDLE h = (HANDLE) _beginthreadex( NULL, // security | 313 | HANDLE h = (HANDLE) _beginthreadex(nullptr, // security |
| 314 | _THREAD_STACK_SIZE, | 314 | _THREAD_STACK_SIZE, |
| 315 | func, | 315 | func, |
| 316 | data, | 316 | data, |
| 317 | 0, // flags (0/CREATE_SUSPENDED) | 317 | 0, // flags (0/CREATE_SUSPENDED) |
| 318 | NULL // thread id (not used) | 318 | nullptr // thread id (not used) |
| 319 | ); | 319 | ); |
| 320 | 320 | ||
| 321 | if( h == NULL) // _beginthreadex returns 0L on failure instead of -1L (like _beginthread) | 321 | if (h == nullptr) // _beginthreadex returns 0L on failure instead of -1L (like _beginthread) |
| 322 | { | 322 | { |
| 323 | FAIL( "CreateThread", GetLastError()); | 323 | FAIL( "CreateThread", GetLastError()); |
| 324 | } | 324 | } |
| @@ -365,7 +365,7 @@ bool THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
| 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 = nullptr; // thread no longer usable |
| 369 | return true; | 369 | return true; |
| 370 | } | 370 | } |
| 371 | // | 371 | // |
| @@ -376,7 +376,7 @@ bool THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
| 376 | // in theory no-one should call this as it is very dangerous (memory and mutex leaks, no notification of DLLs, etc.) | 376 | // in theory no-one should call this as it is very dangerous (memory and mutex leaks, no notification of DLLs, etc.) |
| 377 | if (!TerminateThread( *ref, 0 )) FAIL("TerminateThread", GetLastError()); | 377 | if (!TerminateThread( *ref, 0 )) FAIL("TerminateThread", GetLastError()); |
| 378 | #endif // PLATFORM_XBOX | 378 | #endif // PLATFORM_XBOX |
| 379 | *ref= NULL; | 379 | *ref = nullptr; |
| 380 | } | 380 | } |
| 381 | 381 | ||
| 382 | void THREAD_MAKE_ASYNCH_CANCELLABLE() {} // nothing to do for windows threads, we can cancel them anytime we want | 382 | void THREAD_MAKE_ASYNCH_CANCELLABLE() {} // nothing to do for windows threads, we can cancel them anytime we want |
| @@ -609,7 +609,7 @@ bool THREAD_WAIT_IMPL( THREAD_T *ref, double secs) | |||
| 609 | #define PT_CALL( call ) { int rc= call; if (rc!=0) _PT_FAIL( rc, #call, __FILE__, __LINE__ ); } | 609 | #define PT_CALL( call ) { int rc= call; if (rc!=0) _PT_FAIL( rc, #call, __FILE__, __LINE__ ); } |
| 610 | // | 610 | // |
| 611 | void SIGNAL_INIT( SIGNAL_T *ref ) { | 611 | void SIGNAL_INIT( SIGNAL_T *ref ) { |
| 612 | PT_CALL( pthread_cond_init(ref,NULL /*attr*/) ); | 612 | PT_CALL(pthread_cond_init(ref, nullptr /*attr*/)); |
| 613 | } | 613 | } |
| 614 | void SIGNAL_FREE( SIGNAL_T *ref ) { | 614 | void SIGNAL_FREE( SIGNAL_T *ref ) { |
| 615 | PT_CALL( pthread_cond_destroy(ref) ); | 615 | PT_CALL( pthread_cond_destroy(ref) ); |
| @@ -903,7 +903,7 @@ void THREAD_SET_AFFINITY( unsigned int aff) | |||
| 903 | int bit = 0; | 903 | int bit = 0; |
| 904 | #ifdef __NetBSD__ | 904 | #ifdef __NetBSD__ |
| 905 | cpuset_t *cpuset = cpuset_create(); | 905 | cpuset_t *cpuset = cpuset_create(); |
| 906 | if( cpuset == NULL) | 906 | if (cpuset == nullptr) |
| 907 | _PT_FAIL( errno, "cpuset_create", __FILE__, __LINE__-2 ); | 907 | _PT_FAIL( errno, "cpuset_create", __FILE__, __LINE__-2 ); |
| 908 | #define CPU_SET(b, s) cpuset_set(b, *(s)) | 908 | #define CPU_SET(b, s) cpuset_set(b, *(s)) |
| 909 | #else | 909 | #else |
| @@ -940,7 +940,7 @@ void THREAD_SET_AFFINITY( unsigned int aff) | |||
| 940 | bool 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 = nullptr; |
| 944 | bool done; | 944 | bool done; |
| 945 | 945 | ||
| 946 | // Do timeout counting before the locks | 946 | // Do timeout counting before the locks |
| @@ -959,10 +959,10 @@ bool THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T *mu | |||
| 959 | /* Thread is joinable | 959 | /* Thread is joinable |
| 960 | */ | 960 | */ |
| 961 | if (!timeout) { | 961 | if (!timeout) { |
| 962 | PT_CALL( pthread_join( *ref, NULL /*ignore exit value*/ )); | 962 | PT_CALL(pthread_join(*ref, nullptr /*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, nullptr, timeout); |
| 966 | if ((rc!=0) && (rc!=ETIMEDOUT)) { | 966 | if ((rc!=0) && (rc!=ETIMEDOUT)) { |
| 967 | _PT_FAIL( rc, "PTHREAD_TIMEDJOIN", __FILE__, __LINE__-2 ); | 967 | _PT_FAIL( rc, "PTHREAD_TIMEDJOIN", __FILE__, __LINE__-2 ); |
| 968 | } | 968 | } |
| @@ -1010,9 +1010,9 @@ bool THREAD_WAIT( THREAD_T *ref, double secs , SIGNAL_T *signal_ref, MUTEX_T *mu | |||
| 1010 | __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Cannot make thread async cancellable!"); | 1010 | __android_log_print(ANDROID_LOG_WARN, LOG_TAG, "Cannot make thread async cancellable!"); |
| 1011 | #else | 1011 | #else |
| 1012 | // that's the default, but just in case... | 1012 | // that's the default, but just in case... |
| 1013 | pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); | 1013 | pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, nullptr); |
| 1014 | // we want cancellation to take effect immediately if possible, instead of waiting for a cancellation point (which is the default) | 1014 | // we want cancellation to take effect immediately if possible, instead of waiting for a cancellation point (which is the default) |
| 1015 | pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL); | 1015 | pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, nullptr); |
| 1016 | #endif | 1016 | #endif |
| 1017 | } | 1017 | } |
| 1018 | 1018 | ||
