COSA
An Object-Oriented Platform for Arduino Programming
Mutex.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_NUCLEO_MUTEX_HH
22 #define COSA_NUCLEO_MUTEX_HH
23 
24 #include "Semaphore.hh"
25 
26 namespace Nucleo {
27 
33 class Mutex {
34 public:
40  Mutex(Semaphore& sem) : m_sem(sem) { m_sem.wait(); }
41 
45  ~Mutex() { m_sem.signal(); }
46 
47 private:
48  Semaphore& m_sem;
49 };
50 
51 };
52 
63 #define mutex(s) for (uint8_t i = (s.wait(), 1); i != 0; i--, s.signal())
64 
65 #endif
Definition: Actor.hh:26
void wait(uint8_t count=1)
Definition: Semaphore.cpp:27
void signal(uint8_t count=1, bool flag=true)
Definition: Semaphore.cpp:40
Mutex(Semaphore &sem)
Definition: Mutex.hh:40