|
Revision 2907, 1.7 kB
(checked in by sletz, 2 years ago)
|
Michael Voigt mutex cleanup patch.
|
- Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 |
/* |
|---|
| 2 |
Copyright (C) 2006 Grame |
|---|
| 3 |
|
|---|
| 4 |
This library is free software; you can redistribute it and/or |
|---|
| 5 |
modify it under the terms of the GNU Lesser General Public |
|---|
| 6 |
License as published by the Free Software Foundation; either |
|---|
| 7 |
version 2.1 of the License, or (at your option) any later version. |
|---|
| 8 |
|
|---|
| 9 |
This library is distributed in the hope that it will be useful, |
|---|
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 12 |
Lesser General Public License for more details. |
|---|
| 13 |
|
|---|
| 14 |
You should have received a copy of the GNU Lesser General Public |
|---|
| 15 |
License along with this library; if not, write to the Free Software |
|---|
| 16 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 17 |
|
|---|
| 18 |
Grame Research Laboratory, 9 rue du Garet, 69001 Lyon - France |
|---|
| 19 |
grame@grame.fr |
|---|
| 20 |
*/ |
|---|
| 21 |
|
|---|
| 22 |
#ifndef __JackMutex__ |
|---|
| 23 |
#define __JackMutex__ |
|---|
| 24 |
|
|---|
| 25 |
#include <assert.h> |
|---|
| 26 |
#include "JackError.h" |
|---|
| 27 |
#include "JackPlatformPlug.h" |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
namespace Jack |
|---|
| 31 |
{ |
|---|
| 32 |
/*! |
|---|
| 33 |
\brief Base class for "lockable" objects. |
|---|
| 34 |
*/ |
|---|
| 35 |
|
|---|
| 36 |
class JackLockAble |
|---|
| 37 |
{ |
|---|
| 38 |
|
|---|
| 39 |
private: |
|---|
| 40 |
|
|---|
| 41 |
JackMutex fMutex; |
|---|
| 42 |
|
|---|
| 43 |
protected: |
|---|
| 44 |
|
|---|
| 45 |
JackLockAble() |
|---|
| 46 |
{} |
|---|
| 47 |
~JackLockAble() |
|---|
| 48 |
{} |
|---|
| 49 |
|
|---|
| 50 |
public: |
|---|
| 51 |
|
|---|
| 52 |
void Lock() |
|---|
| 53 |
{ |
|---|
| 54 |
fMutex.Lock(); |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
bool Trylock() |
|---|
| 58 |
{ |
|---|
| 59 |
return fMutex.Trylock(); |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
void Unlock() |
|---|
| 63 |
{ |
|---|
| 64 |
fMutex.Unlock(); |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
}; |
|---|
| 68 |
|
|---|
| 69 |
class JackLock |
|---|
| 70 |
{ |
|---|
| 71 |
private: |
|---|
| 72 |
|
|---|
| 73 |
JackLockAble* fObj; |
|---|
| 74 |
|
|---|
| 75 |
public: |
|---|
| 76 |
|
|---|
| 77 |
JackLock(JackLockAble* obj): fObj(obj) |
|---|
| 78 |
{ |
|---|
| 79 |
fObj->Lock(); |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
JackLock(const JackLockAble* obj): fObj((JackLockAble*)obj) |
|---|
| 83 |
{ |
|---|
| 84 |
fObj->Lock(); |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
~JackLock() |
|---|
| 88 |
{ |
|---|
| 89 |
fObj->Unlock(); |
|---|
| 90 |
} |
|---|
| 91 |
}; |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
} // namespace |
|---|
| 95 |
|
|---|
| 96 |
#endif |
|---|