Debian Codegraph @

avogadro/core/sharedmutex.h

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 #ifndef AVOGADRO_CORE_SHAREDMUTEX_H
7 #define AVOGADRO_CORE_SHAREDMUTEX_H
8
9 #include "avogadrocoreexport.h"
10
11 namespace Avogadro::Core {
12
13 /**
14 * @class SharedMutex sharedmutex.h <avogadro/core/sharedmutex.h>
15 * @brief The SharedMutex class provides a simple wrapper for the C++17
16 * shared_mutex class
17 * @author Marcus D. Hanwell
18 *
19 * A very simple, and thin wrapper around the C++17 shared_mutex class, allowing
20 * for lock, tryLock and unlock.
21 */
22
23 class AVOGADROCORE_EXPORT SharedMutex
24 {
25 public:
26 SharedMutex();
27 ~SharedMutex();
28
29 /**
30 * @brief Obtain a shared read lock.
31 */
32 void lockForRead();
33
34 /**
35 * @brief Attempt to obtain a shared read lock.
36 * @return True on success, false on failure.
37 */
38 bool tryLockForRead();
39
40 /**
41 * @brief Unlocks the exclusive write lock.
42 */
43 void unlockForRead();
44
45 /**
46 * @brief Obtain an exclusive write lock.
47 */
48 void lockForWrite();
49
50 /**
51 * @brief Attempt to obtain an exclusive write lock.
52 * @return True on success, false on failure.
53 */
54 bool tryLockForWrite();
55
56 /**
57 * @brief Unlocks the exclusive write lock.
58 */
59 void unlockForWrite();
60
61 private:
62 class PIMPL;
63 PIMPL* d;
64 };
65 } // namespace Avogadro::Core
66
67 #endif // AVOGADRO_CORE_SHAREDMUTEX_H