Jack2 1.9.6
|
00001 /* 00002 Copyright (C) 2006 Grame 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Lesser General Public 00006 License as published by the Free Software Foundation; either 00007 version 2.1 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Lesser General Public License for more details. 00013 00014 You should have received a copy of the GNU Lesser General Public 00015 License along with this library; if not, write to the Free Software 00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 Grame Research Laboratory, 9 rue du Garet, 69001 Lyon - France 00019 grame@grame.fr 00020 */ 00021 00022 #ifndef __JackMutex__ 00023 #define __JackMutex__ 00024 00025 #include <assert.h> 00026 #include "JackError.h" 00027 #include "JackPlatformPlug.h" 00028 00029 00030 namespace Jack 00031 { 00036 class JackLockAble 00037 { 00038 00039 protected: 00040 00041 JackMutex fMutex; 00042 00043 JackLockAble() 00044 {} 00045 ~JackLockAble() 00046 {} 00047 00048 public: 00049 00050 void Lock() 00051 { 00052 fMutex.Lock(); 00053 } 00054 00055 bool Trylock() 00056 { 00057 return fMutex.Trylock(); 00058 } 00059 00060 void Unlock() 00061 { 00062 fMutex.Unlock(); 00063 } 00064 00065 }; 00066 00067 class JackLock 00068 { 00069 private: 00070 00071 JackLockAble* fObj; 00072 00073 public: 00074 00075 JackLock(JackLockAble* obj): fObj(obj) 00076 { 00077 fObj->Lock(); 00078 } 00079 00080 JackLock(const JackLockAble* obj): fObj((JackLockAble*)obj) 00081 { 00082 fObj->Lock(); 00083 } 00084 00085 ~JackLock() 00086 { 00087 fObj->Unlock(); 00088 } 00089 }; 00090 00091 00092 } // namespace 00093 00094 #endif