PLCnext API Documentation 23.6.0.37
LockGuard.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Commons/Threading/Mutex.hpp"
9
10namespace Arp { namespace System { namespace Commons { namespace Threading
11{
12
15{
16public: // 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
31private: // fields
32 Mutex& mutex;
33};
34
36// inline methods of class Mutex
37
38inline 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(void)
Destructs this instance and releases the lock.
Definition: LockGuard.hpp:44
LockGuard & operator=(const LockGuard &arg)=delete
Assignment operator.
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