RecursiveMutex.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 #ifndef __RECURSIVEMUTEX__
00023 #define __RECURSIVEMUTEX__
00024 
00025 #include <pthread.h>
00026 #include "Lock.hxx"
00027 
00028 namespace CLAM
00029 {
00030 
00031         struct xtime;
00032 
00033         class RecursiveMutex
00034         {
00035         public:
00036                 
00037                 friend class Hidden::LockOps<RecursiveMutex>;
00038 
00039                 typedef Hidden::LockOps<RecursiveMutex> LockOps;
00040                 typedef Hidden::ScopedLock<RecursiveMutex> ScopedLock;
00041 
00042                 RecursiveMutex();
00043 
00044                 ~RecursiveMutex();
00045 
00046         public:
00047                 struct ConditionVar
00048                 {
00049                         long count;
00050                         pthread_mutex_t* pmutex;
00051                 };
00052         private:
00053                 void DoLock();
00054                 void DoUnlock();
00055                 void DoLock( ConditionVar& state );
00056                 void DoUnlock( ConditionVar& state );
00057 
00058                 pthread_mutex_t mMutex;
00059                 unsigned mCount;
00060                 pthread_cond_t mUnlocked;
00061                 pthread_t      mThreadID;
00062                 bool           mValidID;
00063         };
00064 
00065         class RecursiveTryMutex
00066         {
00067         public:
00068                 friend class Hidden::LockOps<RecursiveTryMutex>;
00069 
00070                 typedef Hidden::ScopedLock<RecursiveTryMutex> ScopedLock;
00071                 typedef Hidden::ScopedTryLock<RecursiveTryMutex> ScopedTryLock;
00072 
00073                 RecursiveTryMutex();
00074 
00075                 ~RecursiveTryMutex();
00076 
00077         private:
00078                 struct ConditionVar
00079                 {
00080                         long count;
00081                         pthread_mutex_t* pmutex;
00082                 };
00083 
00084                 void DoLock();
00085                 bool DoTryLock();
00086                 void DoUnlock();
00087                 void DoLock( ConditionVar& state );
00088                 void DoUnlock( ConditionVar& state );
00089 
00090                 pthread_mutex_t mMutex;
00091                 unsigned mCount;
00092                 pthread_cond_t mUnlocked;
00093                 pthread_t      mThreadID;
00094                 bool           mValidID;
00095         };
00096 
00097         class RecursiveTimedMutex
00098         {
00099         public:
00100                 friend class Hidden::LockOps<RecursiveTimedMutex>;
00101 
00102                 typedef Hidden::ScopedLock<RecursiveTimedMutex> ScopedLock;
00103                 typedef Hidden::ScopedTryLock<RecursiveTimedMutex> ScopedTryLock;
00104                 typedef Hidden::ScopedTimedLock<RecursiveTimedMutex> ScopedTimedLock;
00105 
00106                 RecursiveTimedMutex();
00107 
00108                 ~RecursiveTimedMutex();
00109 
00110         private:
00111                 struct ConditionVar
00112                 {
00113                         long count;
00114                         pthread_mutex_t* pmutex;
00115                 };
00116 
00117                 void DoLock();
00118                 bool DoTryLock();
00119                 bool DoTimedLock( const xtime& xt );
00120                 void DoUnlock();
00121                 void DoLock( ConditionVar& state );
00122                 void DoUnlock( ConditionVar& state );
00123 
00124                 pthread_mutex_t mMutex;
00125                 unsigned mCount;
00126                 pthread_cond_t mUnlocked;
00127                 pthread_t      mThreadID;
00128                 bool           mValidID;
00129         };
00130 
00131 } // namespace CLAM
00132 
00133 
00134 #endif // RecursiveMutex.hxx
00135 
Generated by  doxygen 1.6.3