Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

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.6 2003/12/14 09:07:55 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 
00071    virtual inline void unlock()
00072    {
00073       if ( m_owner.same() ) {
00074          m_lockCount--;
00075          if ( ! m_lockCount ) {
00076             m_owner.invalidate();
00077             Mutex::unlock();
00078          }
00079       }
00080    }
00081 };
00082 
00083 }
00084 #endif
00085 /* end of wefts_rmutex.h */

Generated on Mon Dec 22 04:12:30 2003 for Wefts by doxygen1.2.18