@@ -13,26 +13,38 @@ * file. */ #include "objfw-defs.h" -#include "platform.h" +#import "macros.h" + +/** @file */ #if defined(OF_HAVE_PTHREADS) # include -typedef pthread_once_t of_once_t; -# define OF_ONCE_INIT PTHREAD_ONCE_INIT +typedef pthread_once_t OFOnceControl; +# define OFOnceControlInitValue PTHREAD_ONCE_INIT #elif defined(OF_HAVE_ATOMIC_OPS) -typedef volatile int of_once_t; -# define OF_ONCE_INIT 0 +typedef volatile int OFOnceControl; +# define OFOnceControlInitValue 0 #elif defined(OF_AMIGAOS) || !defined(OF_HAVE_THREADS) -typedef int of_once_t; -# define OF_ONCE_INIT 0 +typedef int OFOnceControl; +# define OFOnceControlInitValue 0 #endif + +typedef void (*OFOnceFunction)(void); #ifdef __cplusplus extern "C" { #endif -extern void of_once(of_once_t *control, void (*func)(void)); +/** + * @brief A method to call a function only once in a thread-safe manner. + * + * @param control The once control. This needs to be set to + * OFOnceControlInitValue at compile time. + * @param func The function to call only once + */ +extern void OFOnce(OFOnceControl *_Nonnull control, + OFOnceFunction _Nonnull func); #ifdef __cplusplus } #endif