Index: src/OFOnce.h ================================================================== --- src/OFOnce.h +++ src/OFOnce.h @@ -30,9 +30,17 @@ #endif #ifdef __cplusplus extern "C" { #endif -extern void OFOnce(OFOnceControl *control, void (*func)(void)); +/** + * @brief Executes the specified function exactly once in the application's + * lifetime, even in a multi-threaded environment. + * + * @param control An OFOnceControl. This should be a static variable + * preinitialized to `OFOnceControlInitValue`. + * @param function The function to execute once + */ +extern void OFOnce(OFOnceControl *control, void (*function)(void)); #ifdef __cplusplus } #endif Index: src/OFOnce.m ================================================================== --- src/OFOnce.m +++ src/OFOnce.m @@ -26,26 +26,26 @@ #ifdef OF_AMIGAOS # include #endif void -OFOnce(OFOnceControl *control, void (*func)(void)) +OFOnce(OFOnceControl *control, void (*function)(void)) { #if !defined(OF_HAVE_THREADS) if (*control == 0) { - func(); + function(); *control = 1; } #elif defined(OF_HAVE_PTHREADS) - pthread_once(control, func); + pthread_once(control, function); #elif defined(OF_HAVE_ATOMIC_OPS) /* Avoid atomic operations in case it's already done. */ if (*control == 2) return; if (OFAtomicIntCompareAndSwap(control, 0, 1)) { - func(); + function(); OFMemoryBarrier(); OFAtomicIntIncrease(control); } else @@ -73,12 +73,12 @@ } Permit(); if (run) { - func(); + function(); *control = 2; } #else # error No OFOnce available #endif }