forked from cryfs/cryfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCombinedLock.h
More file actions
36 lines (28 loc) · 866 Bytes
/
CombinedLock.h
File metadata and controls
36 lines (28 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef MESSMER_CPPUTILS_LOCK_COMBINEDLOCK_H
#define MESSMER_CPPUTILS_LOCK_COMBINEDLOCK_H
#include "../macros.h"
namespace cpputils {
/**
* This class is used to combine multiple locks into one, taking care that they are locked/unlocked
* in the order they were given to the constructor.
*/
class CombinedLock final {
public:
CombinedLock(std::unique_lock<std::mutex> *outer, std::unique_lock<std::mutex> *inner)
: _outer(outer), _inner(inner) {
}
void lock() {
_outer->lock();
_inner->lock();
}
void unlock() {
_inner->unlock();
_outer->unlock();
}
private:
std::unique_lock<std::mutex> *_outer;
std::unique_lock<std::mutex> *_inner;
DISALLOW_COPY_AND_ASSIGN(CombinedLock);
};
}
#endif