@@ -65,11 +65,11 @@ #elif defined(_WIN32) # define of_thread_is_current(t) (t == GetCurrentThread()) # define of_thread_current GetCurrentThread #endif -static OF_INLINE BOOL +static OF_INLINE bool of_thread_new(of_thread_t *thread, id (*function)(id), id data) { #if defined(OF_HAVE_PTHREADS) return !pthread_create(thread, NULL, (void*(*)(void*))function, (__bridge void*)data); @@ -79,38 +79,38 @@ return (thread != NULL); #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_thread_join(of_thread_t thread) { #if defined(OF_HAVE_PTHREADS) void *ret; if (pthread_join(thread, &ret)) - return NO; + return false; return (ret != PTHREAD_CANCELED); #elif defined(_WIN32) if (WaitForSingleObject(thread, INFINITE)) - return NO; + return false; CloseHandle(thread); - return YES; + return true; #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_thread_detach(of_thread_t thread) { #if defined(OF_HAVE_PTHREADS) return !pthread_detach(thread); #elif defined(_WIN32) /* FIXME */ - return YES; + return true; #endif } static OF_INLINE void of_thread_exit(void) @@ -120,144 +120,144 @@ #elif defined(_WIN32) ExitThread(0); #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_mutex_new(of_mutex_t *mutex) { #if defined(OF_HAVE_PTHREADS) return !pthread_mutex_init(mutex, NULL); #elif defined(_WIN32) InitializeCriticalSection(mutex); - return YES; + return true; #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_mutex_free(of_mutex_t *mutex) { #if defined(OF_HAVE_PTHREADS) return !pthread_mutex_destroy(mutex); #elif defined(_WIN32) DeleteCriticalSection(mutex); - return YES; + return true; #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_mutex_lock(of_mutex_t *mutex) { #if defined(OF_HAVE_PTHREADS) return !pthread_mutex_lock(mutex); #elif defined(_WIN32) EnterCriticalSection(mutex); - return YES; + return true; #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_mutex_trylock(of_mutex_t *mutex) { #if defined(OF_HAVE_PTHREADS) return !pthread_mutex_trylock(mutex); #elif defined(_WIN32) return TryEnterCriticalSection(mutex); #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_mutex_unlock(of_mutex_t *mutex) { #if defined(OF_HAVE_PTHREADS) return !pthread_mutex_unlock(mutex); #elif defined(_WIN32) LeaveCriticalSection(mutex); - return YES; + return true; #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_condition_new(of_condition_t *condition) { #if defined(OF_HAVE_PTHREADS) return !pthread_cond_init(condition, NULL); #elif defined(_WIN32) condition->count = 0; if ((condition->event = CreateEvent(NULL, FALSE, 0, NULL)) == NULL) - return NO; + return false; - return YES; + return true; #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_condition_wait(of_condition_t *condition, of_mutex_t *mutex) { #if defined(OF_HAVE_PTHREADS) return !pthread_cond_wait(condition, mutex); #elif defined(_WIN32) if (!of_mutex_unlock(mutex)) - return NO; + return false; of_atomic_inc_int(&condition->count); if (WaitForSingleObject(condition->event, INFINITE) != WAIT_OBJECT_0) { of_mutex_lock(mutex); - return NO; + return false; } of_atomic_dec_int(&condition->count); if (!of_mutex_lock(mutex)) - return NO; + return false; - return YES; + return true; #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_condition_signal(of_condition_t *condition) { #if defined(OF_HAVE_PTHREADS) return !pthread_cond_signal(condition); #elif defined(_WIN32) return SetEvent(condition->event); #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_condition_broadcast(of_condition_t *condition) { #if defined(OF_HAVE_PTHREADS) return !pthread_cond_broadcast(condition); #elif defined(_WIN32) size_t i; for (i = 0; i < condition->count; i++) if (!SetEvent(condition->event)) - return NO; + return false; - return YES; + return true; #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_condition_free(of_condition_t *condition) { #if defined(OF_HAVE_PTHREADS) return !pthread_cond_destroy(condition); #elif defined(_WIN32) if (condition->count) - return NO; + return false; return CloseHandle(condition->event); #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_tlskey_new(of_tlskey_t *key) { #if defined(OF_HAVE_PTHREADS) return !pthread_key_create(key, NULL); #elif defined(_WIN32) @@ -273,44 +273,44 @@ #elif defined(_WIN32) return TlsGetValue(key); #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_tlskey_set(of_tlskey_t key, void *ptr) { #if defined(OF_HAVE_PTHREADS) return !pthread_setspecific(key, ptr); #elif defined(_WIN32) return TlsSetValue(key, ptr); #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_tlskey_free(of_tlskey_t key) { #if defined(OF_HAVE_PTHREADS) return !pthread_key_delete(key); #elif defined(_WIN32) return TlsFree(key); #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_spinlock_new(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) *spinlock = 0; - return YES; + return true; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return !pthread_spin_init(spinlock, 0); #else return of_mutex_new(spinlock); #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_spinlock_trylock(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) return of_atomic_cmpswap_int(spinlock, 0, 1); #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) @@ -318,20 +318,20 @@ #else return of_mutex_trylock(spinlock); #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_spinlock_lock(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) # if defined(OF_HAVE_SCHED_YIELD) || defined(_WIN32) int i; for (i = 0; i < OF_SPINCOUNT; i++) if (of_spinlock_trylock(spinlock)) - return YES; + return true; while (!of_spinlock_trylock(spinlock)) # ifndef _WIN32 sched_yield(); # else @@ -339,152 +339,155 @@ # endif # else while (!of_spinlock_trylock(spinlock)); # endif - return YES; + return true; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return !pthread_spin_lock(spinlock); #else return of_mutex_lock(spinlock); #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_spinlock_unlock(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) *spinlock = 0; - return YES; + return true; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return !pthread_spin_unlock(spinlock); #else return of_mutex_unlock(spinlock); #endif } -static OF_INLINE BOOL +static OF_INLINE bool of_spinlock_free(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) - return YES; + return true; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return !pthread_spin_destroy(spinlock); #else return of_mutex_free(spinlock); #endif } #ifdef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES -static OF_INLINE BOOL +static OF_INLINE bool of_rmutex_new(of_mutex_t *mutex) { pthread_mutexattr_t attr; if (pthread_mutexattr_init(&attr)) - return NO; + return false; if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)) - return NO; + return false; if (pthread_mutex_init(mutex, &attr)) - return NO; + return false; if (pthread_mutexattr_destroy(&attr)) - return NO; + return false; - return YES; + return true; } # define of_rmutex_lock of_mutex_lock # define of_rmutex_trylock of_mutex_trylock # define of_rmutex_unlock of_mutex_unlock # define of_rmutex_free of_mutex_free #else -static OF_INLINE BOOL +static OF_INLINE bool of_rmutex_new(of_rmutex_t *rmutex) { if (!of_mutex_new(&rmutex->mutex)) - return NO; + return false; if (!of_tlskey_new(&rmutex->count)) - return NO; + return false; - return YES; + return true; } -static OF_INLINE BOOL +static OF_INLINE bool of_rmutex_lock(of_rmutex_t *rmutex) { uintptr_t count = (uintptr_t)of_tlskey_get(rmutex->count); if (count > 0) { if (!of_tlskey_set(rmutex->count, (void*)(count + 1))) - return NO; - return YES; + return false; + + return true; } if (!of_mutex_lock(&rmutex->mutex)) - return NO; + return false; if (!of_tlskey_set(rmutex->count, (void*)1)) { of_mutex_unlock(&rmutex->mutex); - return NO; + return false; } - return YES; + return true; } -static OF_INLINE BOOL +static OF_INLINE bool of_rmutex_trylock(of_rmutex_t *rmutex) { uintptr_t count = (uintptr_t)of_tlskey_get(rmutex->count); if (count > 0) { if (!of_tlskey_set(rmutex->count, (void*)(count + 1))) - return NO; - return YES; + return false; + + return true; } if (!of_mutex_trylock(&rmutex->mutex)) - return NO; + return false; if (!of_tlskey_set(rmutex->count, (void*)1)) { of_mutex_unlock(&rmutex->mutex); - return NO; + return false; } - return YES; + return true; } -static OF_INLINE BOOL +static OF_INLINE bool of_rmutex_unlock(of_rmutex_t *rmutex) { uintptr_t count = (uintptr_t)of_tlskey_get(rmutex->count); if (count > 1) { if (!of_tlskey_set(rmutex->count, (void*)(count - 1))) - return NO; - return YES; + return false; + + return true; } if (!of_tlskey_set(rmutex->count, (void*)0)) - return NO; + return false; if (!of_mutex_unlock(&rmutex->mutex)) - return NO; + return false; - return YES; + return true; } -static OF_INLINE BOOL +static OF_INLINE bool of_rmutex_free(of_rmutex_t *rmutex) { if (!of_mutex_free(&rmutex->mutex)) - return NO; + return false; if (!of_tlskey_free(rmutex->count)) - return NO; + return false; - return YES; + return true; } #endif