rt 0.19.0

A real-time operating system capable of full preemption
Documentation
#include <rt/notify.h>

#include <rt/trace.h>

void rt_notify_post(struct rt_notify *note)
{
    rt_sem_post(&note->sem);
}

void rt_notify_or(struct rt_notify *note, uint32_t value)
{
    const uint32_t old =
        rt_atomic_fetch_or(&note->value, value, RT_ATOMIC_RELAXED);
    rt_trace_notify_or(note, old, value, old | value);
    rt_notify_post(note);
}

void rt_notify_set(struct rt_notify *note, uint32_t value)
{
    const uint32_t old =
        rt_atomic_exchange(&note->value, value, RT_ATOMIC_RELAXED);
    rt_trace_notify_set(note, old, value);
    rt_notify_post(note);
}

uint32_t rt_notify_wait(struct rt_notify *note)
{
    rt_sem_wait(&note->sem);
    return rt_atomic_load(&note->value, RT_ATOMIC_RELAXED);
}

uint32_t rt_notify_wait_clear(struct rt_notify *note, uint32_t clear)
{
    rt_sem_wait(&note->sem);
    const uint32_t old =
        rt_atomic_fetch_and(&note->value, ~clear, RT_ATOMIC_RELAXED);
    rt_trace_notify_clear(note, old, clear, old & ~clear);
    return old;
}

bool rt_notify_trywait(struct rt_notify *note, uint32_t *value)
{
    if (!rt_sem_trywait(&note->sem))
    {
        return false;
    }
    *value = rt_atomic_load(&note->value, RT_ATOMIC_RELAXED);
    return true;
}

bool rt_notify_trywait_clear(struct rt_notify *note, uint32_t *value,
                             uint32_t clear)
{
    if (!rt_sem_trywait(&note->sem))
    {
        return false;
    }
    const uint32_t old =
        rt_atomic_fetch_and(&note->value, ~clear, RT_ATOMIC_RELAXED);
    *value = old;
    rt_trace_notify_clear(note, old, clear, old & ~clear);
    return true;
}

bool rt_notify_timedwait(struct rt_notify *note, uint32_t *value,
                         unsigned long ticks)
{
    if (!rt_sem_timedwait(&note->sem, ticks))
    {
        return false;
    }
    *value = rt_atomic_load(&note->value, RT_ATOMIC_RELAXED);
    return true;
}

bool rt_notify_timedwait_clear(struct rt_notify *note, uint32_t *value,
                               uint32_t clear, unsigned long ticks)
{
    if (!rt_sem_timedwait(&note->sem, ticks))
    {
        return false;
    }
    const uint32_t old =
        rt_atomic_fetch_and(&note->value, ~clear, RT_ATOMIC_RELAXED);
    *value = old;
    rt_trace_notify_clear(note, old, clear, old & ~clear);
    return true;
}