1 #ifndef LIBFILEZILLA_MUTEX_HEADER
2 #define LIBFILEZILLA_MUTEX_HEADER
11 #include "glue/windows.hpp"
17 #ifdef LFZ_DEBUG_MUTEXES
24 struct FZ_PUBLIC_SYMBOL mutex_debug final
26 mutex_debug(mutex* mtx)
30 static void record_lock(
void* m);
31 static void record_unlock(
void* m);
36 std::vector<std::tuple<std::weak_ptr<mutex_debug>, std::vector<void*>>> order_;
51 class FZ_PUBLIC_SYMBOL
mutex final
54 explicit mutex(
bool recursive =
true);
78 #ifdef LFZ_DEBUG_MUTEXES
80 std::shared_ptr<mutex_debug> h_;
99 EnterCriticalSection(m_);
101 pthread_mutex_lock(m_);
103 #ifdef LFZ_DEBUG_MUTEXES
104 mutex_debug::record_lock(m_);
111 #ifdef LFZ_DEBUG_MUTEXES
112 mutex_debug::record_unlock(m_);
115 LeaveCriticalSection(m_);
117 pthread_mutex_unlock(m_);
130 locked_ = op.locked_;
139 locked_ = op.locked_;
153 EnterCriticalSection(m_);
155 pthread_mutex_lock(m_);
157 #ifdef LFZ_DEBUG_MUTEXES
158 mutex_debug::record_lock(m_);
170 #ifdef LFZ_DEBUG_MUTEXES
171 mutex_debug::record_unlock(m_);
174 LeaveCriticalSection(m_);
176 pthread_mutex_unlock(m_);
184 CRITICAL_SECTION * m_;
186 pthread_mutex_t * m_;
246 CONDITION_VARIABLE cond_;
248 pthread_cond_t cond_;
Waitable condition variable.
Definition: mutex.hpp:196
void wait(scoped_lock &l)
Wait indefinitely for condition to become signalled.
bool wait(scoped_lock &l, duration const &timeout)
Wait until timeout for condition to become signalled.
bool signalled(scoped_lock const &) const
Check if condition is already signalled.
Definition: mutex.hpp:243
void signal(scoped_lock &l)
Signal condition variable.
The duration class represents a time interval in milliseconds.
Definition: time.hpp:291
Lean replacement for std::(recursive_)mutex.
Definition: mutex.hpp:52
void unlock()
Beware, manual locking isn't exception safe, use scoped_lock.
bool try_lock()
Beware, manual locking isn't exception safe.
void lock()
Beware, manual locking isn't exception safe, use scoped_lock.
A simple scoped lock.
Definition: mutex.hpp:93
void unlock()
Releases the mutex.
Definition: mutex.hpp:167
void lock()
Obtains the mutex.
Definition: mutex.hpp:149
Sets some global macros and further includes string.hpp.
The namespace used by libfilezilla.
Definition: apply.hpp:17
Assorted classes dealing with time.