rt 0.17.0

A real-time operating system capable of full preemption
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <rt/once.h>

void rt_once_call(struct rt_once *once, void (*fn)(void))
{
    if (rt_atomic_load(&once->done, RT_ATOMIC_ACQUIRE) == 0)
    {
        rt_mutex_lock(&once->mutex);
        // A mutex has acquire-release semantics, so we can load relaxed here.
        if (rt_atomic_load(&once->done, RT_ATOMIC_RELAXED) == 0)
        {
            fn();
            // This release pairs with the acquire in the fast path.
            rt_atomic_store(&once->done, 1, RT_ATOMIC_RELEASE);
        }
        rt_mutex_unlock(&once->mutex);
    }
}