Jack2 1.9.10

JackMutex.h

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(const char* name = NULL)
00044             :fMutex(name)
00045         {}
00046         ~JackLockAble()
00047         {}
00048 
00049     public:
00050 
00051         bool Lock()
00052         {
00053             return fMutex.Lock();
00054         }
00055 
00056         bool Trylock()
00057         {
00058             return fMutex.Trylock();
00059         }
00060 
00061         bool Unlock()
00062         {
00063             return fMutex.Unlock();
00064         }
00065 
00066 };
00067 
00068 class JackLock
00069 {
00070     private:
00071 
00072         JackLockAble* fObj;
00073 
00074     public:
00075 
00076         JackLock(JackLockAble* obj): fObj(obj)
00077         {
00078             fObj->Lock();
00079         }
00080 
00081         JackLock(const JackLockAble* obj): fObj((JackLockAble*)obj)
00082         {
00083             fObj->Lock();
00084         }
00085 
00086         ~JackLock()
00087         {
00088             fObj->Unlock();
00089         }
00090 };
00091 
00092 
00093 } // namespace
00094 
00095 #endif