PLCnext API Documentation  22.9.0.33
LockGuard.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Commons/Threading/Mutex.hpp"
9 
10 namespace Arp { namespace System { namespace Commons { namespace Threading
11 {
12 
14 class LockGuard
15 {
16 public: // construction/destruction
17 
20  LockGuard(Mutex& mutex);
21 
23  LockGuard(const LockGuard& arg) = delete;
24 
26  LockGuard& operator=(const LockGuard& arg) = delete;
27 
29  ~LockGuard(void);
30 
31 private: // fields
32  Mutex& mutex;
33 };
34 
36 // inline methods of class Mutex
37 
38 inline LockGuard::LockGuard(Mutex& mutexArg)
39  : mutex(mutexArg)
40 {
41  this->mutex.Lock();
42 }
43 
45 {
46  this->mutex.Unlock();
47 }
48 
49 }}}} // end of namespace Arp::System::Commons::Threading
Simple lock guard, acquiring lock on construction and release it on destruction.
Definition: LockGuard.hpp:15
LockGuard & operator=(const LockGuard &arg)=delete
Assignment operator.
~LockGuard(void)
Destructs this instance and releases the lock.
Definition: LockGuard.hpp:44
LockGuard(Mutex &mutex)
Constructs an LockGuard instance and acquires the assgned lock.
Definition: LockGuard.hpp:38
LockGuard(const LockGuard &arg)=delete
Copy constructor.
Mutual exclusion object to prevent data from concurrent modifications.
Definition: Mutex.hpp:26
void Lock(void)
Tries to acquire the lock.
void Unlock(void)
Releases the lock.
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API