|
|
|
@ -713,7 +713,8 @@ struct thread_queue_t
|
|
|
|
|
} THREADNAME_INFO;
|
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
|
#define _GNU_SOURCE //< @r-lyeh: pthread_setname_np()
|
|
|
|
|
#endif
|
|
|
|
@ -737,7 +738,7 @@ thread_id_t thread_current_thread_id( void )
|
|
|
|
|
|
|
|
|
|
return (void*) (uintptr_t)GetCurrentThreadId();
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
return (void*) pthread_self();
|
|
|
|
|
|
|
|
|
@ -753,7 +754,7 @@ void thread_yield( void )
|
|
|
|
|
|
|
|
|
|
SwitchToThread();
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
sched_yield();
|
|
|
|
|
|
|
|
|
@ -769,7 +770,7 @@ void thread_exit( int return_code )
|
|
|
|
|
|
|
|
|
|
ExitThread( (DWORD) return_code );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
pthread_exit( (void*)(uintptr_t) return_code );
|
|
|
|
|
|
|
|
|
@ -810,13 +811,13 @@ thread_ptr_t thread_init( int (*thread_proc)( void* ), void* user_data, char con
|
|
|
|
|
|
|
|
|
|
return (thread_ptr_t) handle;
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
pthread_t thread;
|
|
|
|
|
if( 0 != pthread_create( &thread, NULL, ( void* (*)( void * ) ) thread_proc, user_data ) )
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
#if !defined( __APPLE__ ) && !defined( __EMSCRIPTEN__ ) && !defined( EMSCRIPTEN ) // max doesn't support pthread_setname_np. alternatives? //< @r-lyeh, ems
|
|
|
|
|
#if !defined( __APPLE__ ) && !defined( __EMSCRIPTEN__ ) // max doesn't support pthread_setname_np. alternatives? //< @r-lyeh, ems
|
|
|
|
|
if( name ) pthread_setname_np( thread, name );
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
@ -835,7 +836,7 @@ void thread_term( thread_ptr_t thread )
|
|
|
|
|
WaitForSingleObject( (HANDLE) thread, INFINITE );
|
|
|
|
|
CloseHandle( (HANDLE) thread );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
pthread_join( (pthread_t) thread, NULL );
|
|
|
|
|
|
|
|
|
@ -854,7 +855,7 @@ int thread_join( thread_ptr_t thread )
|
|
|
|
|
GetExitCodeThread( (HANDLE) thread, &retval );
|
|
|
|
|
return (int) retval;
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
void* retval;
|
|
|
|
|
pthread_join( (pthread_t) thread, &retval );
|
|
|
|
@ -872,7 +873,7 @@ int thread_detach( thread_ptr_t thread )
|
|
|
|
|
|
|
|
|
|
return CloseHandle( (HANDLE) thread ) != 0;
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN )
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
return pthread_detach( (pthread_t) thread ) == 0;
|
|
|
|
|
|
|
|
|
@ -888,7 +889,7 @@ void thread_set_high_priority( void )
|
|
|
|
|
|
|
|
|
|
SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_HIGHEST );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
struct sched_param sp;
|
|
|
|
|
memset( &sp, 0, sizeof( sp ) );
|
|
|
|
@ -913,7 +914,7 @@ void thread_mutex_init( thread_mutex_t* mutex )
|
|
|
|
|
|
|
|
|
|
InitializeCriticalSectionAndSpinCount( (CRITICAL_SECTION*) mutex, 32 );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
// Compile-time size check
|
|
|
|
|
struct x { char thread_mutex_type_too_small : ( sizeof( thread_mutex_t ) < sizeof( pthread_mutex_t ) ? 0 : 1 ); };
|
|
|
|
@ -932,7 +933,7 @@ void thread_mutex_term( thread_mutex_t* mutex )
|
|
|
|
|
|
|
|
|
|
DeleteCriticalSection( (CRITICAL_SECTION*) mutex );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
pthread_mutex_destroy( (pthread_mutex_t*) mutex );
|
|
|
|
|
|
|
|
|
@ -948,7 +949,7 @@ void thread_mutex_lock( thread_mutex_t* mutex )
|
|
|
|
|
|
|
|
|
|
EnterCriticalSection( (CRITICAL_SECTION*) mutex );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
pthread_mutex_lock( (pthread_mutex_t*) mutex );
|
|
|
|
|
|
|
|
|
@ -964,7 +965,7 @@ void thread_mutex_unlock( thread_mutex_t* mutex )
|
|
|
|
|
|
|
|
|
|
LeaveCriticalSection( (CRITICAL_SECTION*) mutex );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
pthread_mutex_unlock( (pthread_mutex_t*) mutex );
|
|
|
|
|
|
|
|
|
@ -986,7 +987,7 @@ struct thread_internal_signal_t
|
|
|
|
|
HANDLE event;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
pthread_mutex_t mutex;
|
|
|
|
|
pthread_cond_t condition;
|
|
|
|
@ -1018,7 +1019,7 @@ void thread_signal_init( thread_signal_t* signal )
|
|
|
|
|
internal->event = CreateEvent( NULL, FALSE, FALSE, NULL );
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
pthread_mutex_init( &internal->mutex, NULL );
|
|
|
|
|
pthread_cond_init( &internal->condition, NULL );
|
|
|
|
@ -1042,7 +1043,7 @@ void thread_signal_init( thread_signal_t* signal )
|
|
|
|
|
CloseHandle( internal->event );
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
pthread_mutex_destroy( &internal->mutex );
|
|
|
|
|
pthread_cond_destroy( &internal->condition );
|
|
|
|
@ -1068,7 +1069,7 @@ void thread_signal_raise( thread_signal_t* signal )
|
|
|
|
|
SetEvent( internal->event );
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
pthread_mutex_lock( &internal->mutex );
|
|
|
|
|
internal->value = 1;
|
|
|
|
@ -1103,7 +1104,7 @@ int thread_signal_wait( thread_signal_t* signal, int timeout_ms )
|
|
|
|
|
return !failed;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
struct timespec ts;
|
|
|
|
|
if( timeout_ms >= 0 )
|
|
|
|
@ -1147,7 +1148,7 @@ int thread_atomic_int_load( thread_atomic_int_t* atomic )
|
|
|
|
|
|
|
|
|
|
return InterlockedCompareExchange( &atomic->i, 0, 0 );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
return (int)__sync_fetch_and_add( &atomic->i, 0 );
|
|
|
|
|
|
|
|
|
@ -1163,7 +1164,7 @@ void thread_atomic_int_store( thread_atomic_int_t* atomic, int desired )
|
|
|
|
|
|
|
|
|
|
InterlockedExchange( &atomic->i, desired );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
__sync_fetch_and_and( &atomic->i, 0 );
|
|
|
|
|
__sync_fetch_and_or( &atomic->i, desired );
|
|
|
|
@ -1180,7 +1181,7 @@ int thread_atomic_int_inc( thread_atomic_int_t* atomic )
|
|
|
|
|
|
|
|
|
|
return InterlockedIncrement( &atomic->i ) - 1;
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
return (int)__sync_fetch_and_add( &atomic->i, 1 );
|
|
|
|
|
|
|
|
|
@ -1196,7 +1197,7 @@ int thread_atomic_int_dec( thread_atomic_int_t* atomic )
|
|
|
|
|
|
|
|
|
|
return InterlockedDecrement( &atomic->i ) + 1;
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
return (int)__sync_fetch_and_sub( &atomic->i, 1 );
|
|
|
|
|
|
|
|
|
@ -1212,7 +1213,7 @@ int thread_atomic_int_add( thread_atomic_int_t* atomic, int value )
|
|
|
|
|
|
|
|
|
|
return InterlockedExchangeAdd ( &atomic->i, value );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
return (int)__sync_fetch_and_add( &atomic->i, value );
|
|
|
|
|
|
|
|
|
@ -1228,7 +1229,7 @@ int thread_atomic_int_sub( thread_atomic_int_t* atomic, int value )
|
|
|
|
|
|
|
|
|
|
return InterlockedExchangeAdd( &atomic->i, -value );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
return (int)__sync_fetch_and_sub( &atomic->i, value );
|
|
|
|
|
|
|
|
|
@ -1244,7 +1245,7 @@ int thread_atomic_int_swap( thread_atomic_int_t* atomic, int desired )
|
|
|
|
|
|
|
|
|
|
return InterlockedExchange( &atomic->i, desired );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
int old = (int)__sync_lock_test_and_set( &atomic->i, desired );
|
|
|
|
|
__sync_lock_release( &atomic->i );
|
|
|
|
@ -1262,7 +1263,7 @@ int thread_atomic_int_compare_and_swap( thread_atomic_int_t* atomic, int expecte
|
|
|
|
|
|
|
|
|
|
return InterlockedCompareExchange( &atomic->i, desired, expected );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
return (int)__sync_val_compare_and_swap( &atomic->i, expected, desired );
|
|
|
|
|
|
|
|
|
@ -1278,7 +1279,7 @@ void* thread_atomic_ptr_load( thread_atomic_ptr_t* atomic )
|
|
|
|
|
|
|
|
|
|
return InterlockedCompareExchangePointer( &atomic->ptr, 0, 0 );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
return __sync_fetch_and_add( &atomic->ptr, 0 );
|
|
|
|
|
|
|
|
|
@ -1300,7 +1301,7 @@ void thread_atomic_ptr_store( thread_atomic_ptr_t* atomic, void* desired )
|
|
|
|
|
#pragma warning( pop )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
__sync_lock_test_and_set( &atomic->ptr, desired );
|
|
|
|
|
__sync_lock_release( &atomic->ptr );
|
|
|
|
@ -1322,7 +1323,7 @@ void* thread_atomic_ptr_swap( thread_atomic_ptr_t* atomic, void* desired )
|
|
|
|
|
return InterlockedExchangePointer( &atomic->ptr, desired );
|
|
|
|
|
#pragma warning( pop )
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
void* old = __sync_lock_test_and_set( &atomic->ptr, desired );
|
|
|
|
|
__sync_lock_release( &atomic->ptr );
|
|
|
|
@ -1340,7 +1341,7 @@ void* thread_atomic_ptr_compare_and_swap( thread_atomic_ptr_t* atomic, void* exp
|
|
|
|
|
|
|
|
|
|
return InterlockedCompareExchangePointer( &atomic->ptr, desired, expected );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
return __sync_val_compare_and_swap( &atomic->ptr, expected, desired );
|
|
|
|
|
|
|
|
|
@ -1367,7 +1368,7 @@ void thread_timer_init( thread_timer_t* timer )
|
|
|
|
|
|
|
|
|
|
*(HANDLE*)timer = CreateWaitableTimer( NULL, TRUE, NULL );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
// Nothing
|
|
|
|
|
|
|
|
|
@ -1387,7 +1388,7 @@ void thread_timer_term( thread_timer_t* timer )
|
|
|
|
|
if( timeGetDevCaps( &tc, sizeof( TIMECAPS ) ) == TIMERR_NOERROR )
|
|
|
|
|
timeEndPeriod( tc.wPeriodMin );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
// Nothing
|
|
|
|
|
|
|
|
|
@ -1407,7 +1408,7 @@ void thread_timer_wait( thread_timer_t* timer, THREAD_U64 nanoseconds )
|
|
|
|
|
(void) b;
|
|
|
|
|
WaitForSingleObject( *(HANDLE*)timer, INFINITE );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
struct timespec rem;
|
|
|
|
|
struct timespec req;
|
|
|
|
@ -1432,7 +1433,7 @@ thread_tls_t thread_tls_create( void )
|
|
|
|
|
else
|
|
|
|
|
return (thread_tls_t) (uintptr_t) tls;
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
pthread_key_t tls;
|
|
|
|
|
if( pthread_key_create( &tls, NULL ) == 0 )
|
|
|
|
@ -1452,7 +1453,7 @@ void thread_tls_destroy( thread_tls_t tls )
|
|
|
|
|
|
|
|
|
|
TlsFree( (DWORD) (uintptr_t) tls );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
pthread_key_delete( (pthread_key_t) (uintptr_t) tls ); //< @r-lyeh: uintptr_t
|
|
|
|
|
|
|
|
|
@ -1468,7 +1469,7 @@ void thread_tls_set( thread_tls_t tls, void* value )
|
|
|
|
|
|
|
|
|
|
TlsSetValue( (DWORD) (uintptr_t) tls, value );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
pthread_setspecific( (pthread_key_t) (uintptr_t) tls, value ); //< @r-lyeh: uintptr_t
|
|
|
|
|
|
|
|
|
@ -1484,7 +1485,7 @@ void* thread_tls_get( thread_tls_t tls )
|
|
|
|
|
|
|
|
|
|
return TlsGetValue( (DWORD) (uintptr_t) tls );
|
|
|
|
|
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) || defined( EMSCRIPTEN ) //< @r-lyeh, ems
|
|
|
|
|
#elif defined( __linux__ ) || defined( __APPLE__ ) || defined( __ANDROID__ ) || defined( __EMSCRIPTEN__ ) //< @r-lyeh, ems
|
|
|
|
|
|
|
|
|
|
return pthread_getspecific( (pthread_key_t) (uintptr_t) tls ); //< @r-lyeh: uintptr_t
|
|
|
|
|
|
|
|
|
|