Overview
| Comment: | Make OFOnce() public |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
28230080b3888888c63a3cfca4822f59 |
| User & Date: | js on 2022-06-18 17:30:36 |
| Other Links: | manifest | tags |
Context
|
2022-06-18
| ||
| 17:41 | Remove OFThreadPool (check-in: 06763e3c67 user: js tags: trunk) | |
| 17:30 | Make OFOnce() public (check-in: 28230080b3 user: js tags: trunk) | |
| 01:07 | OFPlugin: Fix accidentally removed = (check-in: c96f67f694 user: js tags: trunk) | |
Changes
Modified src/OFOnce.h from [fee56e64fa] to [3af1572f79].
| ︙ | ︙ | |||
28 29 30 31 32 33 34 |
typedef int OFOnceControl;
# define OFOnceControlInitValue 0
#endif
#ifdef __cplusplus
extern "C" {
#endif
| > > > > > > > > | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
typedef int OFOnceControl;
# define OFOnceControlInitValue 0
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* @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
|
Modified src/OFOnce.m from [a3ef1477f9] to [72d5ba7049].
| ︙ | ︙ | |||
24 25 26 27 28 29 30 | #endif #ifdef OF_AMIGAOS # include <proto/exec.h> #endif void | | | | | | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#endif
#ifdef OF_AMIGAOS
# include <proto/exec.h>
#endif
void
OFOnce(OFOnceControl *control, void (*function)(void))
{
#if !defined(OF_HAVE_THREADS)
if (*control == 0) {
function();
*control = 1;
}
#elif defined(OF_HAVE_PTHREADS)
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)) {
function();
OFMemoryBarrier();
OFAtomicIntIncrease(control);
} else
while (*control == 1)
OFYieldThread();
|
| ︙ | ︙ | |||
71 72 73 74 75 76 77 |
Forbid();
}
}
Permit();
if (run) {
| | | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
Forbid();
}
}
Permit();
if (run) {
function();
*control = 2;
}
#else
# error No OFOnce available
#endif
}
|