Arduino-Scheduler
Portable Collaborative Multi-Tasking Scheduler for Arduino
Semaphore.h
Go to the documentation of this file.
1 
19 #ifndef SCHEDULER_SEMAPHORE_H
20 #define SCHEDULER_SEMAPHORE_H
21 
22 #include <Scheduler.h>
23 
24 class Semaphore {
25 public:
30  Semaphore(unsigned int count = 1) : m_count(count) {}
31 
36  void wait(unsigned int count = 1)
37  {
38  await(m_count >= count);
39  m_count -= count;
40  }
41 
46  void signal(unsigned int count = 1)
47  {
48  m_count += count;
49  Scheduler.yield();
50  }
51 
52 protected:
53  volatile unsigned int m_count;
54 };
55 
56 #endif
void wait(unsigned int count=1)
Definition: Semaphore.h:36
#define await(cond)
Definition: Scheduler.h:162
volatile unsigned int m_count
Definition: Semaphore.h:53
Semaphore(unsigned int count=1)
Definition: Semaphore.h:30
unsigned long count
static void yield()
Definition: Scheduler.cpp:117
SchedulerClass Scheduler
Definition: Scheduler.cpp:53
void signal(unsigned int count=1)
Definition: Semaphore.h:46