1#ifndef LIBFILEZILLA_MUTEX_HEADER
2#define LIBFILEZILLA_MUTEX_HEADER
11#include "glue/windows.hpp"
17#ifdef LFZ_DEBUG_MUTEXES
28struct FZ_PUBLIC_SYMBOL lock_order final {
29 std::vector<mutex*> mutexes_;
30 std::vector<void*> backtrace_;
34struct FZ_PUBLIC_SYMBOL mutex_debug final
36 static void record_lock(
void* m);
37 static void record_unlock(
void* m);
40 std::thread::id id_{};
41 std::vector<std::list<lock_order>::iterator> own_orders_;
56class FZ_PUBLIC_SYMBOL mutex final
59 explicit mutex(
bool recursive =
true);
62 mutex(mutex
const&) =
delete;
63 mutex& operator=(mutex
const&) =
delete;
75 friend class condition;
76 friend class scoped_lock;
83#ifdef LFZ_DEBUG_MUTEXES
97class FZ_PUBLIC_SYMBOL scoped_lock final
105 explicit scoped_lock(
mutex& m)
109 EnterCriticalSection(m_);
111 pthread_mutex_lock(m_);
113#ifdef LFZ_DEBUG_MUTEXES
114 mutex_debug::record_lock(m_);
118 explicit scoped_lock(
mutex& m, flag)
129#ifdef LFZ_DEBUG_MUTEXES
130 mutex_debug::record_unlock(m_);
133 LeaveCriticalSection(m_);
135 pthread_mutex_unlock(m_);
141 scoped_lock(scoped_lock
const&) =
delete;
142 scoped_lock& operator=(scoped_lock
const&) =
delete;
144 scoped_lock(scoped_lock && op)
noexcept
148 locked_ = op.locked_;
152 scoped_lock& operator=(scoped_lock && op)
noexcept
157 locked_ = op.locked_;
171 EnterCriticalSection(m_);
173 pthread_mutex_lock(m_);
175#ifdef LFZ_DEBUG_MUTEXES
176 mutex_debug::record_lock(m_);
187#ifdef LFZ_DEBUG_MUTEXES
188 mutex_debug::record_unlock(m_);
191 LeaveCriticalSection(m_);
193 pthread_mutex_unlock(m_);
197 explicit operator bool()
const {
return locked_; }
200 friend class condition;
203 CRITICAL_SECTION * m_;
205 pthread_mutex_t * m_;
214class FZ_PUBLIC_SYMBOL condition final
220 condition(condition
const&) =
delete;
221 condition& operator=(condition
const&) =
delete;
265 CONDITION_VARIABLE cond_;
267 pthread_cond_t cond_;
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:262
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:57
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:98
void unlock()
Releases the mutex.
Definition mutex.hpp:184
void lock()
Obtains the mutex.
Definition mutex.hpp:167
Sets some global macros and further includes string.hpp.
The namespace used by libfilezilla.
Definition apply.hpp:17
Assorted classes dealing with time.