00001 /* 00002 wefts_rwmutex.h 00003 Read/write Non Reentrant Mutex object header file. 00004 00005 $Id: wefts_rwmutex.h,v 1.10 2004/03/28 21:45:40 jonnymind Exp $ 00006 --------------------------------------------- 00007 Begin : 2003-08-02 20:58 00008 Author : Giancarlo Niccolai 00009 00010 Last modified because: 00011 00012 */ 00013 00014 /************************************************************************** 00015 * This program is free software; you can redistribute it and/or modify * 00016 * it under the terms of the GNU Library General Public License as * 00017 * published by the Free Software Foundation; either version 2.1 of the * 00018 * License, or (at your option) any later version. * 00019 ***************************************************************************/ 00020 00021 #ifndef WT_RWMUTEX_H 00022 #define WT_RWMUTEX_H 00023 00024 #include <wefts_cleanup.h> 00025 #include <wefts_mutex.h> 00026 #include <wefts_cond.h> 00027 #include <wefts_error.h> 00028 00029 #ifndef NO_ASSERTION 00030 #include <cassert> 00031 #endif 00032 00033 namespace Wefts { 00034 00066 class RWMutex: public CleanupHandler 00067 { 00068 protected: 00069 Mutex m_mutex; 00070 Condition m_condRead; 00071 Condition m_condWrite; 00072 00073 int m_locking; 00074 int m_waitingRead; 00075 int m_waitingWrite; 00076 int m_promoting; 00077 00078 public: 00080 RWMutex(); 00081 00098 virtual bool lockRead( double time = 0.0 ); 00099 00106 virtual bool tryLockRead(); 00107 00108 00127 virtual bool lockWrite( double time =0.0 ); 00128 00140 virtual bool tryLockWrite(); 00141 00142 00175 virtual bool promote( double time = 0.0 ) throw( InvalidError ); 00176 00183 virtual bool tryPromote(); 00184 00185 00199 void degrade() throw( InvalidError ); 00200 00208 virtual void unlock() throw ( InvalidError ); 00209 00210 virtual void handleCleanup( int code, void *caller = 0 ); 00211 }; 00212 00213 } 00214 00215 #endif 00216 /* end of wefts_rwmutex.h */