wefts_rmutex.h

Go to the documentation of this file.
00001 /* 00002 wefts_rmutex.h 00003 Reentrant Mutex object header file. 00004 00005 $Id: wefts_rmutex.h,v 1.8 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_RMUTEX_H 00022 #define WT_RMUTEX_H 00023 00024 #include <wefts_mutex.h> 00025 00026 namespace Wefts { 00027 00041 class RMutex: public Mutex { 00042 private: 00043 OSThread m_owner; 00044 volatile int m_lockCount; 00045 00046 public: 00048 RMutex(): Mutex() { m_lockCount = 0;} 00049 00056 virtual inline void lock() 00057 { 00058 if ( m_owner.same() ) m_lockCount++; 00059 else { 00060 Mutex::lock(); 00061 m_owner.setCurrent(); 00062 m_lockCount = 1; 00063 } 00064 } 00065 00077 virtual inline bool trylock() 00078 { 00079 if ( m_owner.same() ) { 00080 m_lockCount++; 00081 return true; 00082 } 00083 else { 00084 if ( Mutex::trylock() ) { 00085 m_owner.setCurrent(); 00086 m_lockCount = 1; 00087 return true; 00088 } 00089 } 00090 return false; 00091 } 00092 00098 virtual inline void unlock() 00099 { 00100 if ( m_owner.same() ) { 00101 m_lockCount--; 00102 if ( ! m_lockCount ) { 00103 m_owner.invalidate(); 00104 Mutex::unlock(); 00105 } 00106 } 00107 } 00108 }; 00109 00110 } 00111 #endif 00112 /* end of wefts_rmutex.h */

Generated on Tue Oct 5 14:57:00 2004 for Wefts by doxygen 1.3.7