mn_timed_lock.hpp
Go to the documentation of this file.
1 
19 #ifndef MINLIB_ESP32_TIMED_LOCK_
20 #define MINLIB_ESP32_TIMED_LOCK_
21 
22 #include "mn_config.hpp"
23 
24 #if MN_THREAD_CONFIG_CONDITION_VARIABLE_SUPPORT == MN_THREAD_CONFIG_YES
25  #include "mn_convar.hpp"
26  #include "mn_convar_task.hpp"
27  #include "mn_autolock.hpp"
28 
29 namespace mn {
33  template<class TLOCK>
35  public:
40  : m_cv(), m_lockObject(), m_bLocked(false) { }
46  }
53  void lock(basic_convar_task& task, unsigned int timeout = MN_THREAD_CONFIG_TIMEOUT_MUTEX_DEFAULT) {
55  while (m_bLocked) {
56  task.wait(m_cv, m_mutex, timeout);
57  }
58  m_bLocked = true;
59  }
65  void unlock(bool signal_childs = true) {
67  m_bLocked = false;
68  m_cv.signal(signal_childs);
69  }
70  private:
72  TLOCK m_lockObject;
73  bool m_bLocked;
74  };
75 
79 
80 }
81 #if MN_THREAD_CONFIG_RECURSIVE_MUTEX == MN_THREAD_CONFIG_YES
82  using timed_remutex_t = basic_timed_lock<remutex_t>;
83 #endif //MN_THREAD_CONFIG_RECURSIVE_MUTEX
84 
85 #endif //MN_THREAD_CONFIG_CONDITION_VARIABLE_SUPPORT
86 #endif //MINLIB_ESP32_TIMED_LOCK_
Definition: mn_lock.hpp:122
Definition: mn_timed_lock.hpp:34
basic_timed_lock()
Definition: mn_timed_lock.hpp:39
~basic_timed_lock()
Definition: mn_timed_lock.hpp:44
bool m_bLocked
Definition: mn_timed_lock.hpp:73
TLOCK m_lockObject
Definition: mn_timed_lock.hpp:72
void lock(basic_convar_task &task, unsigned int timeout=MN_THREAD_CONFIG_TIMEOUT_MUTEX_DEFAULT)
Definition: mn_timed_lock.hpp:53
void unlock(bool signal_childs=true)
Definition: mn_timed_lock.hpp:65
convar_t m_cv
Definition: mn_timed_lock.hpp:71
#define MN_THREAD_CONFIG_TIMEOUT_MUTEX_DEFAULT
Definition: mn_config.hpp:368
basic_condition_variable convar_t
Definition: mn_convar.hpp:106
Definition: mn_allocator_typetraits.hpp:25