Jack2  1.9.8
JackMutex.h
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 {
37 {
38 
39  protected:
40 
41  JackMutex fMutex;
42 
43  JackLockAble()
44  {}
45  ~JackLockAble()
46  {}
47 
48  public:
49 
50  bool Lock()
51  {
52  return fMutex.Lock();
53  }
54 
55  bool Trylock()
56  {
57  return fMutex.Trylock();
58  }
59 
60  bool Unlock()
61  {
62  return fMutex.Unlock();
63  }
64 
65 };
66 
67 class JackLock
68 {
69  private:
70 
71  JackLockAble* fObj;
72 
73  public:
74 
75  JackLock(JackLockAble* obj): fObj(obj)
76  {
77  fObj->Lock();
78  }
79 
80  JackLock(const JackLockAble* obj): fObj((JackLockAble*)obj)
81  {
82  fObj->Lock();
83  }
84 
85  ~JackLock()
86  {
87  fObj->Unlock();
88  }
89 };
90 
91 
92 } // namespace
93 
94 #endif