mn_autolock.hpp
Go to the documentation of this file.
1 
19 #ifndef _MINLIB_AUTOLOCK_H_
20 #define _MINLIB_AUTOLOCK_H_
21 
22 #include "mn_config.hpp"
23 #include "mn_lock.hpp"
24 
25 #include "mn_mutex.hpp"
26 #include "mn_semaphore.hpp"
27 #include "mn_null_lock.hpp"
28 
29 #if (MN_THREAD_CONFIG_RECURSIVE_MUTEX == MN_THREAD_CONFIG_YES)
30  #include "mn_recursive_mutex.hpp"
31 #endif
32 
33 #ifndef portMAX_DELAY
34 #define portMAX_DELAY 0xffffffffUL
35 #endif
36 
37 namespace mn {
42 
47 
52 
53  #if (MN_THREAD_CONFIG_RECURSIVE_MUTEX == MN_THREAD_CONFIG_YES)
54  //using autoremutx_t = basic_autolock<remutex_t>;
55  #endif
56 
57  #if MN_THREAD_CONFIG_LOCK_TYPE == MN_THREAD_CONFIG_MUTEX
58  using LockType_t = mn::mutex_t;
59  #elif MN_THREAD_CONFIG_LOCK_TYPE == MN_THREAD_CONFIG_BINARY_SEMAPHORE
61  #elif MN_THREAD_CONFIG_LOCK_TYPE == MN_THREAD_CONFIG_COUNTING_SEMAPHORE
63  //#elif MN_THREAD_CONFIG_LOCK_TYPE == MN_THREAD_CONFIG_RECURSIVE_MUTEX
64  // using LockType_t = remutex_t;
65  #endif
66 
68 
69  template <class TLOCK = LockType_t>
70  int lock(TLOCK& m1, unsigned int timeout) { return m1.lock(timeout); }
71 
72  template <class TLOCK = LockType_t>
73  int unlock(TLOCK& m1) { return m1.unlock(); }
74 
75  template <class TLOCK = LockType_t>
76  bool try_lock(TLOCK& m1) { return m1.try_lock(); }
77 }
78 
79 #endif
Definition: mn_lock.hpp:122
Definition: mn_binary_semaphore.hpp:29
Definition: mn_allocator_typetraits.hpp:25
basic_mutex mutex_t
Definition: mn_mutex.hpp:76
basic_counting_semaphore counting_semaphore_t
Definition: mn_counting_semaphore.hpp:82
int lock(TLOCK &m1, unsigned int timeout)
Definition: mn_autolock.hpp:70
int unlock(TLOCK &m1)
Definition: mn_autolock.hpp:73
bool try_lock(TLOCK &m1)
Definition: mn_autolock.hpp:76
basic_binary_semaphore binary_semaphore_t
Definition: mn_binary_semaphore.hpp:47