Index: src/threading.h ================================================================== --- src/threading.h +++ src/threading.h @@ -171,10 +171,20 @@ return TlsFree(key); #else # error of_tlskey_free not implemented! #endif } + +static OF_INLINE void +of_thread_yield(void) +{ +#if defined(OF_HAVE_SCHED_YIELD) + sched_yield(); +#elif defined(OF_WINDOWS) + Sleep(0); +#endif +} static OF_INLINE bool of_spinlock_new(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) @@ -201,26 +211,18 @@ static OF_INLINE bool of_spinlock_lock(of_spinlock_t *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) -# if defined(OF_HAVE_SCHED_YIELD) || defined(OF_WINDOWS) size_t i; for (i = 0; i < OF_SPINCOUNT; i++) if (of_spinlock_trylock(spinlock)) return true; while (!of_spinlock_trylock(spinlock)) -# ifndef OF_WINDOWS - sched_yield(); -# else - Sleep(0); -# endif -# else - while (!of_spinlock_trylock(spinlock)); -# endif + of_thread_yield(); return true; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return !pthread_spin_lock(spinlock); #else Index: src/threading.m ================================================================== --- src/threading.m +++ src/threading.m @@ -31,20 +31,13 @@ of_once(of_once_t *control, void (*func)(void)) { if (of_atomic_int_cmpswap(control, 0, 1)) { func(); of_atomic_int_inc(control); - } else { + } else while (*control == 1) -# if defined(HAVE_SCHED_YIELD) - sched_yield(); -# elif defined(OF_WINDOWS) - Sleep(0); -# else - ; -# endif - } + of_thread_yield(); } #endif #if !defined(OF_HAVE_RECURSIVE_PTHREAD_MUTEXES) && !defined(OF_WINDOWS) bool