ANNA Suite  2020b
Multipurpose development suite for Telco applications
Semaphore.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_Semaphore_hpp
10 #define anna_core_mt_Semaphore_hpp
11 
12 #include <semaphore.h>
13 
14 #include <anna/core/functions.hpp>
16 #include <anna/core/mt/Safe.hpp>
17 
18 namespace anna {
19 
20 //class RuntimeException;
21 
30 class Semaphore : public Safe {
31 public:
32  // Constructor
43  Semaphore(unsigned int count);
44 
48  virtual ~Semaphore();
49 
57  void wait() noexcept(false);
58 
63  bool tryWait() noexcept(false);
64 
69  void signal() noexcept(false);
70 
75  virtual std::string asString() const ;
76 
77 protected:
84  void lock() noexcept(false) { wait(); }
85 
92  void unlock() { signal(); }
93 
94 private:
95  sem_t a_id;
96 };
97 
98 } //namespace anna
99 
100 #endif
void wait() noexcept(false)
void unlock()
Definition: Semaphore.hpp:92
Semaphore(unsigned int count)
void signal() noexcept(false)
virtual std::string asString() const
Definition: app.hpp:12
bool tryWait() noexcept(false)
Definition: Safe.hpp:23
Definition: Semaphore.hpp:30
virtual ~Semaphore()
void lock() noexcept(false)
Definition: Semaphore.hpp:84