Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound 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.2 2003/08/05 15:40:20 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 
00027 
00028 namespace Wefts {
00029 
00039 class RMutex: public Mutex {
00040 private:
00041    volatile pthread_t   m_owner;
00042    volatile int m_lockCount;
00043 
00044 public:
00046    RMutex(): Mutex() { m_owner = 0; m_lockCount = 0;}
00047 
00054    virtual inline void lock()
00055    {
00056       volatile int thid = pthread_self();
00057       if (m_owner == thid ) m_lockCount++;
00058       else {
00059          Mutex::lock();
00060          m_owner = thid;
00061          m_lockCount = 1;
00062       }
00063    }
00064 
00070    virtual inline void unlock()
00071    {
00072       if ( pthread_self() == pthread_self() ) {
00073          m_lockCount--;
00074          if ( ! m_lockCount ) Mutex::unlock();
00075       }
00076    }
00077 };
00078 
00079 }
00080 #endif
00081 /* end of wefts_rmutex.h */

Generated on Tue Aug 5 18:09:00 2003 for Wefts by doxygen1.2.18