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