mn_basic_semaphore.hpp
Go to the documentation of this file.
1 
19 #ifndef MINLIB_ESP32_BASE_SEMAPHORE_
20 #define MINLIB_ESP32_BASE_SEMAPHORE_
21 
22 #include "mn_config.hpp"
23 
24 #include <time.h>
25 
26 #include "mn_error.hpp"
27 #include "mn_lock.hpp"
29 
30 
31 
32 namespace mn {
33 
41  class basic_semaphore : public ILockObject {
42  public:
47 
48 #if( configSUPPORT_STATIC_ALLOCATION == 0 )
49  basic_semaphore(const basic_semaphore& other);
51 #endif
62  virtual int lock(unsigned int timeout = MN_THREAD_CONFIG_TIMEOUT_SEMAPHORE_DEFAULT);
63 
71  virtual int time_lock(const struct timespec *timeout);
72 
78  virtual int unlock();
79 
85  void* get_handle() { return m_pSpinlock; }
86 
91  int get_error() { return m_iCreateErrorCode; }
92 
93  virtual bool is_initialized() const { return m_pSpinlock != NULL; }
94 
95  #if configQUEUE_REGISTRY_SIZE > 0
96  void set_name(const char* name) { vQueueAddToRegistry(m_pSpinlock, name); }
97  #endif // configQUEUE_REGISTRY_SIZE
98 
99 
104  virtual bool is_locked() const { return m_isLocked; }
105  public:
106 
107  bool operator == (const basic_semaphore &r) const {
108  return m_pSpinlock == r.m_pSpinlock;
109  }
110 
111  bool operator != (const basic_semaphore &r) const {
112  return !operator==(r);
113  }
114 
115  bool operator < (const basic_semaphore &r) const {
116  return m_pSpinlock < r.m_pSpinlock;
117  }
118 
119  bool operator > (const basic_semaphore &r) const {
120  return m_pSpinlock > r.m_pSpinlock;
121  }
122  protected:
124  void set_error(int error) { m_iCreateErrorCode = error; }
125  protected:
129  void* m_pSpinlock;
130 
131  #if( configSUPPORT_STATIC_ALLOCATION == 1 )
132  StaticSemaphore_t m_SemaphoreBasicBuffer;
133  #endif
134 
140  };
141 }
142 
143 #endif // MINLIB_ESP32_BASE_SEMAPHORE_
Definition: mn_lock.hpp:64
Definition: mn_basic_semaphore.hpp:41
virtual bool is_initialized() const
Definition: mn_basic_semaphore.hpp:93
virtual int time_lock(const struct timespec *timeout)
Definition: mn_basic_semaphore.cpp:109
bool operator!=(const basic_semaphore &r) const
Definition: mn_basic_semaphore.hpp:111
bool operator==(const basic_semaphore &r) const
Definition: mn_basic_semaphore.hpp:107
int m_iCreateErrorCode
Definition: mn_basic_semaphore.hpp:138
bool operator<(const basic_semaphore &r) const
Definition: mn_basic_semaphore.hpp:115
void * m_pSpinlock
Definition: mn_basic_semaphore.hpp:129
virtual int unlock()
Definition: mn_basic_semaphore.cpp:88
bool operator>(const basic_semaphore &r) const
Definition: mn_basic_semaphore.hpp:119
bool m_isLocked
Definition: mn_basic_semaphore.hpp:139
virtual int lock(unsigned int timeout=MN_THREAD_CONFIG_TIMEOUT_SEMAPHORE_DEFAULT)
Definition: mn_basic_semaphore.cpp:67
void * get_handle()
Definition: mn_basic_semaphore.hpp:85
void set_error(int error)
Definition: mn_basic_semaphore.hpp:124
int get_error()
Definition: mn_basic_semaphore.hpp:91
basic_semaphore()
Definition: mn_basic_semaphore.cpp:47
virtual bool is_locked() const
Is locked?
Definition: mn_basic_semaphore.hpp:104
#define MN_THREAD_CONFIG_TIMEOUT_SEMAPHORE_DEFAULT
Definition: mn_config.hpp:342
A list of all error codes in this lib. This file is part of the Mini Thread Library (https://github....
Definition: mn_allocator_typetraits.hpp:25