@@ -59,17 +59,17 @@ static OF_INLINE BOOL of_thread_new(of_thread_t *thread, id (*main)(id), id data) { #if defined(OF_HAVE_PTHREADS) - return (pthread_create(thread, NULL, (void*(*)(void*))main, - (void*)data) ? NO : YES); + return !pthread_create(thread, NULL, (void*(*)(void*))main, + (void*)data); #elif defined(_WIN32) *thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)main, (void*)data, 0, NULL); - return (thread == NULL ? NO : YES); + return (thread != NULL); #endif } static OF_INLINE BOOL of_thread_join(of_thread_t thread) @@ -78,11 +78,11 @@ void *ret; if (pthread_join(thread, &ret)) return NO; - return (ret != PTHREAD_CANCELED ? YES : NO); + return (ret != PTHREAD_CANCELED); #elif defined(_WIN32) if (WaitForSingleObject(thread, INFINITE)) return NO; CloseHandle(thread); @@ -103,11 +103,11 @@ static OF_INLINE BOOL of_mutex_new(of_mutex_t *mutex) { #if defined(OF_HAVE_PTHREADS) - return (pthread_mutex_init(mutex, NULL) ? NO : YES); + return !pthread_mutex_init(mutex, NULL); #elif defined(_WIN32) InitializeCriticalSection(mutex); return YES; #endif } @@ -114,11 +114,11 @@ static OF_INLINE BOOL of_mutex_free(of_mutex_t *mutex) { #if defined(OF_HAVE_PTHREADS) - return (pthread_mutex_destroy(mutex) ? NO : YES); + return !pthread_mutex_destroy(mutex); #elif defined(_WIN32) DeleteCriticalSection(mutex); return YES; #endif } @@ -125,11 +125,11 @@ static OF_INLINE BOOL of_mutex_lock(of_mutex_t *mutex) { #if defined(OF_HAVE_PTHREADS) - return (pthread_mutex_lock(mutex) ? NO : YES); + return !pthread_mutex_lock(mutex); #elif defined(_WIN32) EnterCriticalSection(mutex); return YES; #endif } @@ -136,21 +136,21 @@ static OF_INLINE BOOL of_mutex_trylock(of_mutex_t *mutex) { #if defined(OF_HAVE_PTHREADS) - return (pthread_mutex_trylock(mutex) ? NO : YES); + return !pthread_mutex_trylock(mutex); #elif defined(_WIN32) - return (TryEnterCriticalSection(mutex) ? YES : NO); + return TryEnterCriticalSection(mutex); #endif } static OF_INLINE BOOL of_mutex_unlock(of_mutex_t *mutex) { #if defined(OF_HAVE_PTHREADS) - return (pthread_mutex_unlock(mutex) ? NO : YES); + return !pthread_mutex_unlock(mutex); #elif defined(_WIN32) LeaveCriticalSection(mutex); return YES; #endif } @@ -157,11 +157,11 @@ static OF_INLINE BOOL of_condition_new(of_condition_t *condition) { #if defined(OF_HAVE_PTHREADS) - return (pthread_cond_init(condition, NULL) ? NO : YES); + return !pthread_cond_init(condition, NULL); #elif defined(_WIN32) condition->count = 0; if ((condition->event = CreateEvent(NULL, FALSE, 0, NULL)) == NULL) return NO; @@ -168,15 +168,19 @@ return YES; #endif } +#if defined(OF_HAVE_PTHREADS) static OF_INLINE BOOL +#elif defined(_WIN32) +static BOOL +#endif of_condition_wait(of_condition_t *condition, of_mutex_t *mutex) { #if defined(OF_HAVE_PTHREADS) - return (pthread_cond_wait(condition, mutex) ? NO : YES); + return !pthread_cond_wait(condition, mutex); #elif defined(_WIN32) if (!of_mutex_unlock(mutex)) return NO; of_atomic_inc_int(&condition->count); @@ -197,21 +201,25 @@ static OF_INLINE BOOL of_condition_signal(of_condition_t *condition) { #if defined(OF_HAVE_PTHREADS) - return (pthread_cond_signal(condition) ? NO : YES); + return !pthread_cond_signal(condition); #elif defined(_WIN32) - return (SetEvent(condition->event) ? YES : NO); + return SetEvent(condition->event); #endif } +#if defined(OF_HAVE_PTHREADS) static OF_INLINE BOOL +#elif defined(_WIN32) +static BOOL +#endif of_condition_broadcast(of_condition_t *condition) { #if defined(OF_HAVE_PTHREADS) - return (pthread_cond_broadcast(condition) ? NO : YES); + return !pthread_cond_broadcast(condition); #elif defined(_WIN32) size_t i; for (i = 0; i < condition->count; i++) if (!SetEvent(condition->event)) @@ -219,30 +227,34 @@ return YES; #endif } +#if defined(OF_HAVE_PTHREADS) static OF_INLINE BOOL +#elif defined(_WIN32) +static BOOL +#endif of_condition_free(of_condition_t *condition) { #if defined(OF_HAVE_PTHREADS) - return (pthread_cond_destroy(condition) ? NO : YES); + return !pthread_cond_destroy(condition); #elif defined(_WIN32) if (condition->count) return NO; - return (CloseHandle(condition->event) ? YES : NO); + return CloseHandle(condition->event); #endif } static OF_INLINE BOOL of_tlskey_new(of_tlskey_t *key) { #if defined(OF_HAVE_PTHREADS) - return (pthread_key_create(key, NULL) ? NO : YES); + return !pthread_key_create(key, NULL); #elif defined(_WIN32) - return ((*key = TlsAlloc()) == TLS_OUT_OF_INDEXES ? NO : YES); + return ((*key = TlsAlloc()) != TLS_OUT_OF_INDEXES); #endif } static OF_INLINE id of_tlskey_get(of_tlskey_t key) @@ -264,23 +276,23 @@ of_tlskey_set(of_tlskey_t key, id obj) { void *p = (obj != nil ? (void*)obj : NULL); #if defined(OF_HAVE_PTHREADS) - return (pthread_setspecific(key, p) ? NO : YES); + return !pthread_setspecific(key, p); #elif defined(_WIN32) - return (TlsSetValue(key, p) ? YES : NO); + return TlsSetValue(key, p); #endif } static OF_INLINE BOOL of_tlskey_free(of_tlskey_t key) { #if defined(OF_HAVE_PTHREADS) - return (pthread_key_delete(key) ? NO : YES); + return !pthread_key_delete(key); #elif defined(_WIN32) - return (TlsFree(key) ? YES : NO); + return TlsFree(key); #endif } static OF_INLINE BOOL of_spinlock_new(of_spinlock_t *s) @@ -287,23 +299,23 @@ { #if defined(OF_ATOMIC_OPS) *s = 0; return YES; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) - return (pthread_spin_init(s, 0) ? NO : YES); + return !pthread_spin_init(s, 0); #else return of_mutex_new(s); #endif } static OF_INLINE BOOL of_spinlock_trylock(of_spinlock_t *s) { #if defined(OF_ATOMIC_OPS) - return (of_atomic_cmpswap_int(s, 0, 1) ? YES : NO); + return of_atomic_cmpswap_int(s, 0, 1); #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) - return (pthread_spin_trylock(s) ? NO : YES); + return !pthread_spin_trylock(s); #else return of_mutex_trylock(s); #endif } @@ -328,11 +340,11 @@ while (!of_spinlock_trylock(s)); # endif return YES; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) - return (pthread_spin_lock(s) ? NO : YES); + return !pthread_spin_lock(s); #else return of_mutex_lock(s); #endif } @@ -341,11 +353,11 @@ { #if defined(OF_ATOMIC_OPS) *s = 0; return YES; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) - return (pthread_spin_unlock(s) ? NO : YES); + return !pthread_spin_unlock(s); #else return of_mutex_unlock(s); #endif } @@ -353,10 +365,10 @@ of_spinlock_free(of_spinlock_t *s) { #if defined(OF_ATOMIC_OPS) return YES; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) - return (pthread_spin_destroy(s) ? NO : YES); + return !pthread_spin_destroy(s); #else return of_mutex_free(s); #endif }