PLCnext API Documentation 23.6.0.37
AutoResetEvent.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Commons/Threading/LockGuard.hpp"
9
10namespace Arp { namespace System { namespace Commons { namespace Threading
11{
12
13// Forward declaration
14class ConditionVariable;
15
23{
24public: // typedefs
26 typedef std::shared_ptr<AutoResetEvent> Ptr;
27
28public:
31 explicit AutoResetEvent(bool initial = false);
32
34
37 void Set(void);
38
40 void Reset(void);
41
46 bool WaitOne(unsigned long timeoutMs = 0);
47
48private: // methods
49 bool WaitOneInfinite(void);
50 bool TimedWaitOne(unsigned long timeoutMs);
51
52private: // deleted methods
53 AutoResetEvent(const AutoResetEvent&) = delete;
54 AutoResetEvent& operator=(const AutoResetEvent&) = delete;
55
56private: // fields.
57 bool flag;
58 Mutex syncRoot;
59 std::unique_ptr<ConditionVariable> pSignal;
60};
61
63// inline methods of class AutoResetEvent
65{
66 LockGuard lock(this->syncRoot);
67 this->flag = false;
68}
69
70}}}} // end of namespace Arp::System::Commons::Threading
Event object to signal a single thread that an event has occurred. Can be used to synchronize threads...
Definition: AutoResetEvent.hpp:23
bool WaitOne(unsigned long timeoutMs=0)
Suspends thread execution until event is signaled by another thread.
std::shared_ptr< AutoResetEvent > Ptr
Definition of a pointer in the context of an AutoResetEvent.
Definition: AutoResetEvent.hpp:26
AutoResetEvent(bool initial=false)
Creates a new object with specified initial state.
void Set(void)
Sets the event to signaled state.
void Reset(void)
Resets the event state to non-signaled.
Definition: AutoResetEvent.hpp:64
Simple lock guard, acquiring lock on construction and release it on destruction.
Definition: LockGuard.hpp:15
Mutual exclusion object to prevent data from concurrent modifications.
Definition: Mutex.hpp:26
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API