PLCnext API Documentation  22.9.0.33
Semaphore.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 
9 // forwards
10 namespace Arp { namespace System { namespace Ve
11 {
12 class ISemaphoreService;
13 }}}
14 
15 namespace Arp { namespace System { namespace Commons { namespace Threading
16 {
17 
22 class Semaphore
23 {
24 public: // construction/destruction
29  explicit Semaphore(size_t initialValue);
30 
38  Semaphore(const String& name, size_t initialValue);
39 
44  explicit Semaphore(const String& name);
45 
47  virtual ~Semaphore(void);
48 
49 public: // operations
50 
53  void Post(void);
54 
61  bool Wait(size_t timeout = 0);
62 
66  bool TryWait(void);
67 
71  size_t GetValue(void);
72 
75  String GetName(void);
76 
77 private: // deleted methods
78 
80  Semaphore(const Semaphore& arg) = delete;
81 
83  Semaphore& operator=(const Semaphore& arg) = delete;
84 
85 private: // fields
86  Arp::System::Ve::ISemaphoreService* pSemaphoreService;
87 };
88 
90 // inline methods of class Semaphore
91 
92 }}}} // end of namespace Arp::System::Commons::Threading
Implementation of named or unnamed semaphore used to synchronize processes and threads.
Definition: Semaphore.hpp:23
bool TryWait(void)
Like Wait but returns immediately if the semaphore could not be decremented.
Semaphore(size_t initialValue)
Constructs an unnamed Semaphore, i.e. local, instance.
void Post(void)
Increments the internal counter.
String GetName(void)
Returns the name of a named semaphore.
bool Wait(size_t timeout=0)
Tries to decrements the internal counter.
Semaphore(const String &name, size_t initialValue)
Constructs a named Semaphore instance.
Semaphore(const String &name)
Opens a named Semaphore instance.
virtual ~Semaphore(void)
Destructs this instance and frees all resources.
size_t GetValue(void)
Returns the current value of the internal counter.
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API