libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
mutex.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <mutex>
12
14
15class WaitCondition;
16
33class Mutex {
34 public:
41 class Locker {
42 public:
47 Locker(Mutex &mutex) : _mutex(mutex) {
48 _mutex.lock();
49 }
50
53 _mutex.unlock();
54 }
55
56 Locker(const Locker &) = delete;
57 Locker &operator=(const Locker &) = delete;
58 Locker(Locker &&) = delete;
59 Locker &operator=(Locker &&) = delete;
60
61 private:
62 Mutex &_mutex;
63 };
64
66 Mutex() = default;
67
69 ~Mutex() = default;
70
71 Mutex(const Mutex &) = delete;
72 Mutex &operator=(const Mutex &) = delete;
73 Mutex(Mutex &&) = delete;
74 Mutex &operator=(Mutex &&) = delete;
75
77 void lock() {
78 _mutex.lock();
79 }
80
82 void unlock() {
83 _mutex.unlock();
84 }
85
90 bool tryLock() {
91 return _mutex.try_lock();
92 }
93
94 private:
95 friend class WaitCondition;
96 std::mutex _mutex;
97};
98
Dynamic array container wrapping std::vector.
Definition list.h:40
RAII scoped locker for Mutex.
Definition mutex.h:41
Locker(Mutex &mutex)
Constructs a Locker and locks the given mutex.
Definition mutex.h:47
~Locker()
Destructor. Unlocks the mutex.
Definition mutex.h:52
Mutual exclusion lock wrapping std::mutex.
Definition mutex.h:33
Mutex()=default
Constructs an unlocked mutex.
void unlock()
Unlocks the mutex.
Definition mutex.h:82
bool tryLock()
Attempts to lock the mutex without blocking.
Definition mutex.h:90
void lock()
Locks the mutex. Blocks if already locked by another thread.
Definition mutex.h:77
~Mutex()=default
Destructor.
Condition variable wrapping std::condition_variable.
Definition waitcondition.h:26
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19