PLCnext API Documentation 25.0.2.69
Semaphore.hpp
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
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
25 explicit Semaphore(size_t initialValue);
26 Semaphore(const String& name, size_t initialValue);
27 explicit Semaphore(const String& name);
28 virtual ~Semaphore(void);
29
30public: // operations
31 void Post(void);
32 bool Wait(size_t timeout = 0);
33 bool TryWait(void);
34 size_t GetValue(void);
35 String GetName(void);
36
37private: // deleted methods
38
40 Semaphore(const Semaphore& arg) = delete;
41
43 Semaphore& operator=(const Semaphore& arg) = delete;
44
45private: // fields
46 Arp::System::Ve::ISemaphoreService* pSemaphoreService;
47};
48
49}}}} // end of namespace Arp::System::Commons::Threading
This class represents the Arp String. The implementation is based on std::string.
Definition: String.hpp:39
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.
Definition: Semaphore.cpp:106
Semaphore(size_t initialValue)
Constructs an unnamed Semaphore, i.e. local, instance.
Definition: Semaphore.cpp:22
virtual ~Semaphore(void)
Destructs this instance and frees all resources.
Definition: Semaphore.cpp:80
void Post(void)
Increments the internal counter.
Definition: Semaphore.cpp:87
String GetName(void)
Returns the name of a named semaphore.
Definition: Semaphore.cpp:121
bool Wait(size_t timeout=0)
Tries to decrements the internal counter.
Definition: Semaphore.cpp:98
size_t GetValue(void)
Returns the current value of the internal counter.
Definition: Semaphore.cpp:114
Root namespace for the PLCnext API