YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
src
util
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
9
class
simple_mutex
:
public
mutex_interface
{
10
public
:
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
33
private
:
34
bool
_lock;
35
};
36
37
#endif
// _SIMPLE_MUTEX_H_
mutex_interface
Definition
mutex_interface.h:46
simple_mutex
Definition
simple_mutex.h:9
Generated by
1.12.0