Vault
4.1
|
00001 /* 00002 Copyright c1997-2014 Trygve Isaacson. All rights reserved. 00003 This file is part of the Code Vault version 4.1 00004 http://www.bombaydigital.com/ 00005 License: MIT. See LICENSE.md in the Vault top level directory. 00006 */ 00007 00008 #ifndef vmutexlocker_h 00009 #define vmutexlocker_h 00010 00013 #include "vtypes.h" 00014 00015 #include "vstring.h" 00016 00017 class VMutex; 00018 00023 // VMutexLocker ---------------------------------------------------------------- 00024 00066 class VMutexLocker { 00067 public: 00068 00082 VMutexLocker(VMutex* mutex, const VString& name, bool lockInitially = true); 00086 virtual ~VMutexLocker(); 00087 00094 virtual void lock(); 00100 virtual void unlock(); 00105 bool isLocked() const { return mIsLocked; } 00110 VMutex* getMutex() { return mMutex; } 00117 void yield(); 00118 00119 protected: 00120 00121 VMutex* mMutex; 00122 bool mIsLocked; 00123 VString mName; 00124 00125 private: 00126 00127 // Prevent copy construction and assignment since there is no provision for sharing a mutex. 00128 VMutexLocker(const VMutexLocker& other); 00129 VMutexLocker& operator=(const VMutexLocker& other); 00130 }; 00131 00132 // VMutexUnlocker -------------------------------------------------------------- 00133 00139 class VMutexUnlocker : public VMutexLocker { 00140 public: 00141 00154 VMutexUnlocker(VMutex* mutex, bool unlockInitially = true); 00158 virtual ~VMutexUnlocker(); 00159 00160 private: 00161 00162 // Prevent copy construction and assignment since there is no provision for sharing a mutex. 00163 VMutexUnlocker(const VMutexUnlocker& other); 00164 VMutexUnlocker& operator=(const VMutexUnlocker& other); 00165 }; 00166 00167 #endif /* vmutexlocker_h */ 00168