rt/cxx/examples/notify.cpp

40 lines
703 B
C++

#include <rt/notify.hpp>
#include <rt/task.hpp>
#include <rt/trap.hpp>
#include <rt/assert.h>
static const int n = 10;
static rt::notify note(0);
static void notifier(void)
{
rt::task::drop_privilege();
for (int i = 0; i < n; ++i)
{
rt::task::sleep(5);
note.orr(1);
}
rt::task::sleep(15);
note.nop();
}
static void waiter(void)
{
rt::task::drop_privilege();
uint32_t value;
for (int i = 0; i < n; ++i)
{
rt_assert(note.timedwait_clear(value, 1, 10), "wait timed out");
}
rt_assert(!note.timedwait(value, 10), "wait didn't time out");
rt::trap();
}
RT_TASK(notifier, RT_STACK_MIN, 0);
RT_TASK(waiter, RT_STACK_MIN, 0);