MinitScript
0.9.31 PRE-BETA
src
minitscript
os
threading
Mutex.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
minitscript/os/threading/fwd-minitscript.h
>
4
5
#include <
minitscript/minitscript.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
minitscript::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
};
minitscript::os::threading::Mutex
Mutex implementation.
Definition:
Mutex.h:19
minitscript::os::threading::Mutex::Condition
friend class Condition
Definition:
Mutex.h:20
minitscript::os::threading::Mutex::~Mutex
~Mutex()
Destroys the mutex.
Definition:
Mutex.h:35
minitscript::os::threading::Mutex::name
string name
Definition:
Mutex.h:59
minitscript::os::threading::Mutex::unlock
void unlock()
Unlocks this mutex.
Definition:
Mutex.h:54
minitscript::os::threading::Mutex::lock
void lock()
Locks the mutex, additionally mutex locks will block until other locks have been unlocked.
Definition:
Mutex.h:47
minitscript::os::threading::Mutex::stlMutex
mutex stlMutex
Definition:
Mutex.h:60
minitscript::os::threading::Mutex::tryLock
bool tryLock()
Tries to locks the mutex.
Definition:
Mutex.h:40
minitscript.h
_FORBID_CLASS_COPY
#define _FORBID_CLASS_COPY(CLASS)
Definition:
minitscript.h:9
fwd-minitscript.h
Generated by
1.9.1