86 lines
2.1 KiB
C
86 lines
2.1 KiB
C
#include <rt/notify.h>
|
|
|
|
void rt_notify_init(struct rt_notify *note, uint32_t value)
|
|
{
|
|
rt_atomic_store(¬e->value, value, RT_ATOMIC_RELAXED);
|
|
rt_sem_init_binary(¬e->sem);
|
|
}
|
|
|
|
void rt_notify_post(struct rt_notify *note)
|
|
{
|
|
rt_sem_post(¬e->sem);
|
|
}
|
|
|
|
void rt_notify_or(struct rt_notify *note, uint32_t value)
|
|
{
|
|
rt_atomic_fetch_or(¬e->value, value, RT_ATOMIC_RELAXED);
|
|
rt_notify_post(note);
|
|
}
|
|
|
|
void rt_notify_add(struct rt_notify *note, uint32_t value)
|
|
{
|
|
rt_atomic_fetch_add(¬e->value, value, RT_ATOMIC_RELAXED);
|
|
rt_notify_post(note);
|
|
}
|
|
|
|
void rt_notify_set(struct rt_notify *note, uint32_t value)
|
|
{
|
|
rt_atomic_store(¬e->value, value, RT_ATOMIC_RELAXED);
|
|
rt_notify_post(note);
|
|
}
|
|
|
|
uint32_t rt_notify_wait(struct rt_notify *note)
|
|
{
|
|
rt_sem_wait(¬e->sem);
|
|
return rt_atomic_load(¬e->value, RT_ATOMIC_RELAXED);
|
|
}
|
|
|
|
uint32_t rt_notify_wait_clear(struct rt_notify *note, uint32_t clear)
|
|
{
|
|
rt_sem_wait(¬e->sem);
|
|
return rt_atomic_fetch_and(¬e->value, ~clear, RT_ATOMIC_RELAXED);
|
|
}
|
|
|
|
bool rt_notify_trywait(struct rt_notify *note, uint32_t *value)
|
|
{
|
|
if (!rt_sem_trywait(¬e->sem))
|
|
{
|
|
return false;
|
|
}
|
|
*value = rt_atomic_load(¬e->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(¬e->sem))
|
|
{
|
|
return false;
|
|
}
|
|
*value = rt_atomic_fetch_and(¬e->value, ~clear, RT_ATOMIC_RELAXED);
|
|
return true;
|
|
}
|
|
|
|
bool rt_notify_timedwait(struct rt_notify *note, uint32_t *value,
|
|
unsigned long ticks)
|
|
{
|
|
if (!rt_sem_timedwait(¬e->sem, ticks))
|
|
{
|
|
return false;
|
|
}
|
|
*value = rt_atomic_load(¬e->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(¬e->sem, ticks))
|
|
{
|
|
return false;
|
|
}
|
|
*value = rt_atomic_fetch_and(¬e->value, ~clear, RT_ATOMIC_RELAXED);
|
|
return true;
|
|
}
|