TDME2
1.9.200
src
tdme
os
threading
Mutex.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
tdme/os/threading/fwd-tdme.h
>
4
5
#include <
tdme/tdme.h
>
6
7
#include <mutex>
8
#include <string>
9
10
using
std::mutex;
11
using
std::string;
12
13
/**
14
* Mutex implementation.
15
* Mutexes are used to ensure that only one process can run a critical section,
16
* which is e.g. modifying shared data between thread.
17
* @author Andreas Drewke
18
*/
19
class
tdme::os::threading::Mutex
{
20
friend
class
Condition
;
21
22
public
:
23
// forbid class copy
24
FORBID_CLASS_COPY
(
Mutex
)
25
26
/**
27
* @brief Public constructor
28
* @param name name
29
*/
30
inline
Mutex
(const
string
&
name
):
name
(
name
) {};
31
32
/**
33
* @brief Destroys the mutex
34
*/
35
inline
~Mutex
() {}
36
37
/**
38
* @brief Tries to locks the mutex
39
*/
40
inline
bool
tryLock
() {
41
return
stlMutex
.try_lock();
42
}
43
44
/**
45
* @brief Locks the mutex, additionally mutex locks will block until other locks have been unlocked.
46
*/
47
inline
void
lock
() {
48
stlMutex
.lock();
49
}
50
51
/**
52
* @brief Unlocks this mutex
53
*/
54
inline
void
unlock
() {
55
stlMutex
.unlock();
56
}
57
58
private
:
59
string
name
;
60
mutex
stlMutex
;
61
};
tdme::os::threading::Condition
Threading condition variable implementation.
Definition:
Condition.h:23
tdme::os::threading::Mutex
Mutex implementation.
Definition:
Mutex.h:19
tdme::os::threading::Mutex::~Mutex
~Mutex()
Destroys the mutex.
Definition:
Mutex.h:35
tdme::os::threading::Mutex::name
string name
Definition:
Mutex.h:59
tdme::os::threading::Mutex::unlock
void unlock()
Unlocks this mutex.
Definition:
Mutex.h:54
tdme::os::threading::Mutex::lock
void lock()
Locks the mutex, additionally mutex locks will block until other locks have been unlocked.
Definition:
Mutex.h:47
tdme::os::threading::Mutex::stlMutex
mutex stlMutex
Definition:
Mutex.h:60
tdme::os::threading::Mutex::tryLock
bool tryLock()
Tries to locks the mutex.
Definition:
Mutex.h:40
fwd-tdme.h
tdme.h
FORBID_CLASS_COPY
#define FORBID_CLASS_COPY(CLASS)
Definition:
tdme.h:6
Generated by
1.9.1