@@ -12,14 +12,16 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ -#import "objfw-defs.h" +#include "objfw-defs.h" + +#include "platform.h" #if !defined(OF_HAVE_THREADS) || \ - (!defined(OF_HAVE_PTHREADS) && !defined(_WIN32)) + (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS)) # error No threads available! #endif #include @@ -32,11 +34,11 @@ typedef pthread_key_t of_tlskey_t; typedef pthread_mutex_t of_mutex_t; typedef pthread_cond_t of_condition_t; typedef pthread_once_t of_once_t; # define OF_ONCE_INIT PTHREAD_ONCE_INIT -#elif defined(_WIN32) +#elif defined(OF_WINDOWS) /* * winsock2.h needs to be included before windows.h. Not including it here * would make it impossible to use sockets after threading.h has been * imported. */ @@ -69,11 +71,11 @@ #ifdef OF_HAVE_SCHED_YIELD # include #endif -#if defined(OF_HAVE_RECURSIVE_PTHREAD_MUTEXES) || defined(_WIN32) +#if defined(OF_HAVE_RECURSIVE_PTHREAD_MUTEXES) || defined(OF_WINDOWS) # define of_rmutex_t of_mutex_t #else typedef struct { of_mutex_t mutex; of_tlskey_t count; @@ -86,11 +88,11 @@ } of_thread_attr_t; #if defined(OF_HAVE_PTHREADS) # define of_thread_is_current(t) pthread_equal(t, pthread_self()) # define of_thread_current pthread_self -#elif defined(_WIN32) +#elif defined(OF_WINDOWS) # define of_thread_is_current(t) (t == GetCurrentThread()) # define of_thread_current GetCurrentThread #else # error of_thread_is_current not implemented! # error of_thread_current not implemented! @@ -127,11 +129,11 @@ 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) +#elif defined(OF_WINDOWS) return ((*key = TlsAlloc()) != TLS_OUT_OF_INDEXES); #else # error of_tlskey_new not implemented! #endif } @@ -139,11 +141,11 @@ static OF_INLINE void* of_tlskey_get(of_tlskey_t key) { #if defined(OF_HAVE_PTHREADS) return pthread_getspecific(key); -#elif defined(_WIN32) +#elif defined(OF_WINDOWS) return TlsGetValue(key); #else # error of_tlskey_get not implemented! #endif } @@ -151,11 +153,11 @@ 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) +#elif defined(OF_WINDOWS) return TlsSetValue(key, ptr); #else # error of_tlskey_set not implemented! #endif } @@ -163,11 +165,11 @@ static OF_INLINE bool of_tlskey_free(of_tlskey_t key) { #if defined(OF_HAVE_PTHREADS) return !pthread_key_delete(key); -#elif defined(_WIN32) +#elif defined(OF_WINDOWS) return TlsFree(key); #else # error of_tlskey_free not implemented! #endif } @@ -199,19 +201,19 @@ 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) +# if defined(OF_HAVE_SCHED_YIELD) || defined(OF_WINDOWS) int i; for (i = 0; i < OF_SPINCOUNT; i++) if (of_spinlock_trylock(spinlock)) return true; while (!of_spinlock_trylock(spinlock)) -# ifndef _WIN32 +# ifndef OF_WINDOWS sched_yield(); # else Sleep(0); # endif # else