@@ -15,11 +15,11 @@ */ #import "objfw-defs.h" #if !defined(OF_HAVE_THREADS) || \ - (!defined(OF_HAVE_PTHREADS) && !defined(_WIN32)) + (!defined(OF_HAVE_PTHREADS) && !defined(_WIN32)) # error No threads available! #endif #include @@ -40,10 +40,12 @@ typedef CRITICAL_SECTION of_mutex_t; typedef struct { HANDLE event; int count; } of_condition_t; +#else +# error No threads available! #endif #if defined(OF_HAVE_ATOMIC_OPS) # import "atomic.h" typedef volatile int of_spinlock_t; @@ -67,10 +69,13 @@ # define of_thread_is_current(t) pthread_equal(t, pthread_self()) # define of_thread_current pthread_self #elif defined(_WIN32) # 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! #endif static OF_INLINE bool of_thread_new(of_thread_t *thread, id (*function)(id), id data) { @@ -80,10 +85,12 @@ #elif defined(_WIN32) *thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)function, (__bridge void*)data, 0, NULL); return (thread != NULL); +#else +# error of_thread_new not implemented! #endif } static OF_INLINE bool of_thread_join(of_thread_t thread) @@ -104,10 +111,12 @@ return false; CloseHandle(thread); return true; +#else +# error of_thread_join not implemented! #endif } static OF_INLINE bool of_thread_detach(of_thread_t thread) @@ -115,10 +124,12 @@ #if defined(OF_HAVE_PTHREADS) return !pthread_detach(thread); #elif defined(_WIN32) /* FIXME */ return true; +#else +# error of_thread_detach not implemented! #endif } static OF_INLINE void of_thread_exit(void) @@ -125,10 +136,12 @@ { #if defined(OF_HAVE_PTHREADS) pthread_exit(NULL); #elif defined(_WIN32) ExitThread(0); +#else +# error of_thread_exit not implemented! #endif } static OF_INLINE bool of_mutex_new(of_mutex_t *mutex) @@ -136,10 +149,12 @@ #if defined(OF_HAVE_PTHREADS) return !pthread_mutex_init(mutex, NULL); #elif defined(_WIN32) InitializeCriticalSection(mutex); return true; +#else +# error of_mutex_new not implemented! #endif } static OF_INLINE bool of_mutex_free(of_mutex_t *mutex) @@ -147,10 +162,12 @@ #if defined(OF_HAVE_PTHREADS) return !pthread_mutex_destroy(mutex); #elif defined(_WIN32) DeleteCriticalSection(mutex); return true; +#else +# error of_mutex_free not implemented! #endif } static OF_INLINE bool of_mutex_lock(of_mutex_t *mutex) @@ -158,10 +175,12 @@ #if defined(OF_HAVE_PTHREADS) return !pthread_mutex_lock(mutex); #elif defined(_WIN32) EnterCriticalSection(mutex); return true; +#else +# error of_mutex_lock not implemented! #endif } static OF_INLINE bool of_mutex_trylock(of_mutex_t *mutex) @@ -168,10 +187,12 @@ { #if defined(OF_HAVE_PTHREADS) return !pthread_mutex_trylock(mutex); #elif defined(_WIN32) return TryEnterCriticalSection(mutex); +#else +# error of_mutex_trylock not implemented! #endif } static OF_INLINE bool of_mutex_unlock(of_mutex_t *mutex) @@ -179,10 +200,12 @@ #if defined(OF_HAVE_PTHREADS) return !pthread_mutex_unlock(mutex); #elif defined(_WIN32) LeaveCriticalSection(mutex); return true; +#else +# error of_mutex_unlock not implemented! #endif } static OF_INLINE bool of_condition_new(of_condition_t *condition) @@ -194,10 +217,12 @@ if ((condition->event = CreateEvent(NULL, FALSE, 0, NULL)) == NULL) return false; return true; +#else +# error of_condition_new not implemented! #endif } static OF_INLINE bool of_condition_wait(of_condition_t *condition, of_mutex_t *mutex) @@ -219,10 +244,12 @@ if (!of_mutex_lock(mutex)) return false; return true; +#else +# error of_condition_wait not implemented! #endif } static OF_INLINE bool of_condition_timed_wait(of_condition_t *condition, of_mutex_t *mutex, @@ -251,10 +278,12 @@ if (!of_mutex_lock(mutex)) return false; return true; +#else +# error of_condition_timed_wait not implemented! #endif } static OF_INLINE bool of_condition_signal(of_condition_t *condition) @@ -261,10 +290,12 @@ { #if defined(OF_HAVE_PTHREADS) return !pthread_cond_signal(condition); #elif defined(_WIN32) return SetEvent(condition->event); +#else +# error of_condition_signal not implemented! #endif } static OF_INLINE bool of_condition_broadcast(of_condition_t *condition) @@ -277,10 +308,12 @@ for (i = 0; i < condition->count; i++) if (!SetEvent(condition->event)) return false; return true; +#else +# error of_condition_broadcast not implemented! #endif } static OF_INLINE bool of_condition_free(of_condition_t *condition) @@ -290,10 +323,12 @@ #elif defined(_WIN32) if (condition->count) return false; return CloseHandle(condition->event); +#else +# error of_condition_free not implemented! #endif } static OF_INLINE bool of_tlskey_new(of_tlskey_t *key) @@ -300,10 +335,12 @@ { #if defined(OF_HAVE_PTHREADS) return !pthread_key_create(key, NULL); #elif defined(_WIN32) return ((*key = TlsAlloc()) != TLS_OUT_OF_INDEXES); +#else +# error of_tlskey_new not implemented! #endif } static OF_INLINE void* of_tlskey_get(of_tlskey_t key) @@ -310,10 +347,12 @@ { #if defined(OF_HAVE_PTHREADS) return pthread_getspecific(key); #elif defined(_WIN32) return TlsGetValue(key); +#else +# error of_tlskey_get not implemented! #endif } static OF_INLINE bool of_tlskey_set(of_tlskey_t key, void *ptr) @@ -320,10 +359,12 @@ { #if defined(OF_HAVE_PTHREADS) return !pthread_setspecific(key, ptr); #elif defined(_WIN32) return TlsSetValue(key, ptr); +#else +# error of_tlskey_set not implemented! #endif } static OF_INLINE bool of_tlskey_free(of_tlskey_t key) @@ -330,10 +371,12 @@ { #if defined(OF_HAVE_PTHREADS) return !pthread_key_delete(key); #elif defined(_WIN32) return TlsFree(key); +#else +# error of_tlskey_free not implemented! #endif } static OF_INLINE bool of_spinlock_new(of_spinlock_t *spinlock)