Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
Mutex.h
Go to the documentation of this file.
1#pragma once
2
3#include <misc/gen/TimeSpec.h>
4#include <misc/global.h>
5#include <pthread.h>
6#include <string>
7
8namespace sf
9{
10
17{
18 public:
22 typedef ::pthread_mutex_t* handle_type;
23
27 Mutex(const char* name = nullptr);
28
33
37 inline operator handle_type();
38
43 {
44 public:
48 explicit Lock(const Mutex& mutex, bool try_lock = false);
49
54
58 bool acquire(bool try_lock = false, const TimeSpec& timeout = {});
59
64 bool release();
65
70 explicit operator bool() const
71 {
72 return _locked;
73 }
74
75 private:
79 Lock(const Lock& lock);
80
84 Mutex& _mutexRef;
88 bool _locked{false};
89 };
90
91 friend class Condition;
92
93 private:
97 ::pthread_mutex_t _mutex{0};
98
102 Mutex(const Mutex&);
103
107 const Mutex& operator=(const Mutex&);
108
112 bool isMutexDestroyed();
113
117 void clearMutex();
118
122 bool acquire(bool try_lock, const TimeSpec& timeout);
123
127 void release();
128
132 std::string _name;
133
137 pid_t _threadId{-1};
138};
139
143inline Mutex::operator handle_type()
144{
145 return &_mutex;
146}
147
148}// namespace sf
Wrapper for the pthread_cond mechanism.
Definition Condition.h:16
Locking class for easy locking and unlocking by destructor.
Definition Mutex.h:43
~Lock()
Destructor.
bool acquire(bool try_lock=false, const TimeSpec &timeout={})
Returns true when if it was acquired.
Lock(const Mutex &mutex, bool try_lock=false)
Constructor.
Lightweight intra process thread synchronization.
Definition Mutex.h:17
Mutex(const char *name=nullptr)
Default constructor.
~Mutex()
Destructor.
::pthread_mutex_t * handle_type
Handle type.
Definition Mutex.h:22
#define _MISC_CLASS
Definition misc/global.h:40
Definition Application.h:10
Class wrapper for timespec structure to modify.
Definition TimeSpec.h:12