Add semaphore based signal implementation

This commit is contained in:
Henrik Stickann
2022-04-10 15:27:16 +02:00
parent 4b03e1d9f4
commit 47bad524ad
2 changed files with 56 additions and 0 deletions

29
src/os2/signal.cpp Normal file
View File

@@ -0,0 +1,29 @@
#include <sta/os2/signal.hpp>
namespace sta
{
Os2Signal::Os2Signal(osSemaphoreId_t * semaphore)
: semaphore_{semaphore}
{}
void Os2Signal::notify()
{
osSemaphoreRelease(*semaphore_);
}
bool Os2Signal::peek()
{
return (osSemaphoreGetCount(*semaphore_) != 0);
}
bool Os2Signal::test()
{
return (osSemaphoreAcquire(*semaphore_, 0) == osOK);
}
void Os2Signal::wait()
{
osSemaphoreAcquire(*semaphore_, osWaitForever);
}
} // namespace sta