CLAM-Development  1.4.0
RecursiveMutex.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #ifndef __RECURSIVEMUTEX__
23 #define __RECURSIVEMUTEX__
24 
25 #include <pthread.h>
26 #include "Lock.hxx"
27 
28 namespace CLAM
29 {
30 
31  struct xtime;
32 
34  {
35  public:
36 
38 
41 
43 
45 
46  public:
47  struct ConditionVar
48  {
49  long count;
50  pthread_mutex_t* pmutex;
51  };
52  private:
53  void DoLock();
54  void DoUnlock();
55  void DoLock( ConditionVar& state );
56  void DoUnlock( ConditionVar& state );
57 
58  pthread_mutex_t mMutex;
59  unsigned mCount;
60  pthread_cond_t mUnlocked;
61  pthread_t mThreadID;
62  bool mValidID;
63  };
64 
66  {
67  public:
69 
72 
74 
76 
77  private:
78  struct ConditionVar
79  {
80  long count;
81  pthread_mutex_t* pmutex;
82  };
83 
84  void DoLock();
85  bool DoTryLock();
86  void DoUnlock();
87  void DoLock( ConditionVar& state );
88  void DoUnlock( ConditionVar& state );
89 
90  pthread_mutex_t mMutex;
91  unsigned mCount;
92  pthread_cond_t mUnlocked;
93  pthread_t mThreadID;
94  bool mValidID;
95  };
96 
98  {
99  public:
101 
105 
107 
109 
110  private:
111  struct ConditionVar
112  {
113  long count;
114  pthread_mutex_t* pmutex;
115  };
116 
117  void DoLock();
118  bool DoTryLock();
119  bool DoTimedLock( const xtime& xt );
120  void DoUnlock();
121  void DoLock( ConditionVar& state );
122  void DoUnlock( ConditionVar& state );
123 
124  pthread_mutex_t mMutex;
125  unsigned mCount;
126  pthread_cond_t mUnlocked;
127  pthread_t mThreadID;
128  bool mValidID;
129  };
130 
131 } // namespace CLAM
132 
133 
134 #endif // RecursiveMutex.hxx
135