Debian Codegraph @

avogadro/core/sharedmutex.cpp

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #include "sharedmutex.h"
7
8 #include <shared_mutex>
9
10 namespace Avogadro::Core {
11
12 using std::shared_mutex;
13
14 class SharedMutex::PIMPL
15 {
16 public:
17 PIMPL() {}
18
19 shared_mutex lock;
20 };
21
22 SharedMutex::SharedMutex() : d(new PIMPL) {}
23
24 SharedMutex::~SharedMutex()
25 {
26 delete d;
27 }
28
29 void SharedMutex::lockForRead()
30 {
31 d->lock.lock_shared();
32 }
33
34 bool SharedMutex::tryLockForRead()
35 {
36 return d->lock.try_lock_shared();
37 }
38
39 void SharedMutex::unlockForRead()
40 {
41 d->lock.unlock_shared();
42 }
43
44 void SharedMutex::lockForWrite()
45 {
46 d->lock.lock();
47 }
48
49 bool SharedMutex::tryLockForWrite()
50 {
51 return d->lock.try_lock();
52 }
53
54 void SharedMutex::unlockForWrite()
55 {
56 d->lock.unlock();
57 }
58
59 } // namespace Avogadro::Core