YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
simple_mutex.h
1// A simple mutex implementation. It implements
2// a active wait loop if the mutex is locked.
3
4#ifndef _SIMPLE_MUTEX_H_
5#define _SIMPLE_MUTEX_H_
6
7#include "mutex_interface.h"
8
10public:
11
12 simple_mutex() : _lock(false) { }
13 virtual ~simple_mutex() { }
14
15 void lock() override {
16 while(_lock) ;
17 _lock = true;
18 }
19
20 void unlock() override {
21 _lock = false;
22 }
23
24 bool try_lock() override {
25 if (!_lock) {
26 _lock = true;
27 return true;
28 } else {
29 return false;
30 }
31 }
32
33private:
34 bool _lock;
35};
36
37#endif // _SIMPLE_MUTEX_H_