33 lines
786 B
C
33 lines
786 B
C
#pragma once
|
|
|
|
#include <rt/atomic.h>
|
|
#include <rt/mutex.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
struct rt_once;
|
|
|
|
/* Call fn exactly once among all callers using the same struct rt_once.
|
|
* Regardless of which caller actually executes fn, rt_once_call only returns
|
|
* for any caller after fn has returned. */
|
|
void rt_once_call(struct rt_once *once, void (*fn)(void));
|
|
|
|
struct rt_once
|
|
{
|
|
rt_atomic_int done;
|
|
struct rt_mutex mutex;
|
|
};
|
|
|
|
#define RT_ONCE_INIT(name) \
|
|
{ \
|
|
.done = 0, .mutex = RT_MUTEX_INIT(name.mutex), \
|
|
}
|
|
|
|
#define RT_ONCE(name) struct rt_once name = RT_ONCE_INIT(name)
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|