fpmas 1.6
guards.h
Go to the documentation of this file.
1#ifndef FPMAS_SYNCHRO_GUARDS_H
2#define FPMAS_SYNCHRO_GUARDS_H
3
9
10namespace fpmas { namespace synchro {
24 template<typename T>
25 class Guard {
26 protected:
31
38 : mutex(*node->mutex()) {
39 }
40
41 public:
42 Guard(const Guard&) = delete;
43 Guard(Guard&&) = delete;
44 Guard& operator=(const Guard&) = delete;
45 Guard& operator=(Guard&&) = delete;
46
47 virtual ~Guard() {}
48 };
49
53 template<typename T>
54 class ReadGuard : Guard<T> {
55 public:
67 : Guard<T>(const_cast<api::graph::DistributedNode<T>*>(node)) {
68 // updates node.data() according to the SyncMode
69 this->mutex.read();
70 }
71
77 virtual ~ReadGuard() {
78 this->mutex.releaseRead();
79 }
80 };
81
85 template<typename T>
86 class AcquireGuard : Guard<T> {
87 public:
99 : Guard<T>(node) {
100 // updates node.data() according to the SyncMode
101 this->mutex.acquire();
102 }
108 virtual ~AcquireGuard() {
109 this->mutex.releaseAcquire();
110 }
111 };
112
116 template<typename T>
117 class LockGuard : Guard<T> {
118 public:
128 : Guard<T>(node) {
129 this->mutex.lock();
130 }
136 virtual ~LockGuard() {
137 this->mutex.unlock();
138 }
139 };
140
144 template<typename T>
146 public:
156 : Guard<T>(const_cast<api::graph::DistributedNode<T>*>(node)) {
157 this->mutex.lockShared();
158 }
165 this->mutex.unlockShared();
166 }
167 };
168
169
170}}
171#endif
Definition: distributed_node.h:28
Definition: mutex.h:26
Definition: guards.h:86
virtual ~AcquireGuard()
Definition: guards.h:108
AcquireGuard(api::graph::DistributedNode< T > *node)
Definition: guards.h:98
Definition: guards.h:25
api::synchro::Mutex< T > & mutex
Definition: guards.h:30
Guard(api::graph::DistributedNode< T > *node)
Definition: guards.h:37
Definition: guards.h:117
virtual ~LockGuard()
Definition: guards.h:136
LockGuard(api::graph::DistributedNode< T > *node)
Definition: guards.h:127
Definition: guards.h:54
virtual ~ReadGuard()
Definition: guards.h:77
ReadGuard(const api::graph::DistributedNode< T > *node)
Definition: guards.h:66
Definition: guards.h:145
SharedLockGuard(const api::graph::DistributedNode< T > *node)
Definition: guards.h:155
virtual ~SharedLockGuard()
Definition: guards.h:164
Definition: fpmas.cpp:3