@@ -15,23 +15,22 @@ #include "config.h" #include -#import "once.h" +#import "OFOnce.h" +#if defined(OF_HAVE_THREADS) && defined(OF_HAVE_ATOMIC_OPS) +# import "OFAtomic.h" +# import "OFPlainMutex.h" +#endif #ifdef OF_AMIGAOS # include #endif -#if defined(OF_HAVE_THREADS) && defined(OF_HAVE_ATOMIC_OPS) -# import "atomic.h" -# import "mutex.h" -#endif - void -of_once(of_once_t *control, void (*func)(void)) +OFOnce(OFOnceControl *control, void (*func)(void)) { #if !defined(OF_HAVE_THREADS) if (*control == 0) { func(); *control = 1; @@ -41,19 +40,19 @@ #elif defined(OF_HAVE_ATOMIC_OPS) /* Avoid atomic operations in case it's already done. */ if (*control == 2) return; - if (of_atomic_int_cmpswap(control, 0, 1)) { + if (OFAtomicIntCompareAndSwap(control, 0, 1)) { func(); - of_memory_barrier(); + OFMemoryBarrier(); - of_atomic_int_inc(control); + OFAtomicIntIncrease(control); } else while (*control == 1) - of_thread_yield(); + OFYieldThread(); #elif defined(OF_AMIGAOS) bool run = false; /* Avoid Forbid() in case it's already done. */ if (*control == 2) @@ -78,8 +77,8 @@ if (run) { func(); *control = 2; } #else -# error No of_once available +# error No OFOnce available #endif }