ANNA Suite  2020b
Multipurpose development suite for Telco applications
Mutex.hpp
Go to the documentation of this file.
1 // ANNA - Anna is Not Nothingness Anymore //
2 // //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
4 // //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7 
8 
9 #ifndef anna_core_mt_Mutex_hpp
10 #define anna_core_mt_Mutex_hpp
11 
12 #include <pthread.h>
13 
14 #include <anna/core/mt/Safe.hpp>
15 
16 namespace anna {
17 
41 class Mutex : public Safe {
42 public:
43  struct Mode { enum _v { Recursive, Strict }; };
47  explicit Mutex(const Mode::_v mode = Mode::Recursive);
48 
52  virtual ~Mutex();
53 
54  virtual void lock() noexcept(false);
55 
56  virtual void unlock() ;
57 
64  bool trylock() noexcept(false);
65 
70  operator const pthread_mutex_t*() const {
71 #ifdef _MT
72  return &a_id;
73 #else
74  return NULL;
75 #endif
76  }
77 
78 private:
79 #ifdef _MT
80  pthread_mutex_t a_id;
81 #endif
82 
83  Mutex(const Mutex& other);
84 };
85 
93 #define anna_declare_mutex(ClassName) \
94  anna::Mutex a_autoMutex; \
95  void lock () noexcept(false) { a_autoMutex.lock (); } \
96  void unlock () { a_autoMutex.unlock (); } \
97  friend class anna::Guard <ClassName >;
98 
99 #define anna_access_mutex a_autoMutex
100 
101 } //namespace anna
102 
103 #endif
virtual void unlock()
virtual void lock() noexcept(false)
_v
Definition: Mutex.hpp:43
Mutex(const Mode::_v mode=Mode::Recursive)
Definition: Mutex.hpp:43
bool trylock() noexcept(false)
virtual ~Mutex()
Definition: Mutex.hpp:43
Definition: app.hpp:12
Definition: Safe.hpp:23
Definition: Mutex.hpp:41
Definition: Mutex.hpp:43