COSA
An Object-Oriented Platform for Arduino Programming
Semaphore.cpp
Go to the documentation of this file.
1 
21 #include "Semaphore.hh"
22 #include "Thread.hh"
23 
24 using namespace Nucleo;
25 
26 void
27 Semaphore::wait(uint8_t count)
28 {
29  uint8_t key = lock();
30  while (count > m_count) {
31  unlock(key);
32  Thread::s_running->enqueue(&m_queue);
33  key = lock();
34  }
35  m_count -= count;
36  unlock(key);
37 }
38 
39 void
40 Semaphore::signal(uint8_t count, bool flag)
41 {
42  synchronized {
43  m_count += count;
44  }
45  Thread::s_running->dequeue(&m_queue, flag);
46 }
Definition: Actor.hh:26
void wait(uint8_t count=1)
Definition: Semaphore.cpp:27
void dequeue(Head *queue, bool flag=true)
Definition: Thread.cpp:107
void signal(uint8_t count=1, bool flag=true)
Definition: Semaphore.cpp:40
uint8_t lock()
Definition: Types.h:319
void enqueue(Head *queue, Thread *thread=NULL)
Definition: Thread.cpp:98
void unlock(uint8_t key)
Definition: Types.h:331
static Thread * s_running
Definition: Thread.hh:124