PLCnext API Documentation 23.6.0.37
Semaphore.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8
9// forwards
10namespace Arp { namespace System { namespace Ve
11{
12class ISemaphoreService;
13}}}
14
15namespace Arp { namespace System { namespace Commons { namespace Threading
16{
17
23{
24public: // 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
49public: // 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
76
77private: // deleted methods
78
80 Semaphore(const Semaphore& arg) = delete;
81
83 Semaphore& operator=(const Semaphore& arg) = delete;
84
85private: // 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