RWMutexNSPR.h

Go to the documentation of this file.
00001 /****************** <VPR heading BEGIN do not edit this line> *****************
00002  *
00003  * VR Juggler Portable Runtime
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Patrick Hartling, Kevin Meinert, Carolina Cruz-Neira
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile$
00010  * Date modified: $Date: 2005-01-18 08:39:30 -0600 (Tue, 18 Jan 2005) $
00011  * Version:       $Revision: 16639 $
00012  * -----------------------------------------------------------------
00013  *
00014  ****************** <VPR heading END do not edit this line> ******************/
00015 
00016 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00017  *
00018  * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
00019  *
00020  * Original Authors:
00021  *   Allen Bierbaum, Christopher Just,
00022  *   Patrick Hartling, Kevin Meinert,
00023  *   Carolina Cruz-Neira, Albert Baker
00024  *
00025  * This library is free software; you can redistribute it and/or
00026  * modify it under the terms of the GNU Library General Public
00027  * License as published by the Free Software Foundation; either
00028  * version 2 of the License, or (at your option) any later version.
00029  *
00030  * This library is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00033  * Library General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU Library General Public
00036  * License along with this library; if not, write to the
00037  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00038  * Boston, MA 02111-1307, USA.
00039  *
00040  *************** <auto-copyright.pl END do not edit this line> ***************/
00041 
00042 #ifndef _VPR_RW_MUTEX_NSPR_H_
00043 #define _VPR_RW_MUTEX_NSPR_H_
00044 
00045 #include <vpr/vprConfig.h>
00046 
00047 #include <stdio.h>
00048 #include <prrwlock.h>
00049 
00050 #include <vpr/Util/ReturnStatus.h>
00051 
00052 
00053 namespace vpr
00054 {
00055 
00061 class VPR_CLASS_API RWMutexNSPR
00062 {
00063 public:
00064    RWMutexNSPR() : mRwLock(NULL)
00065    {
00066       // Note the second argument "VPR RW Mutex" is for debug purposes only
00067       mRwLock = PR_NewRWLock(0, "VPR RW Mutex");
00068    }
00069 
00070    ~RWMutexNSPR()
00071    {
00072       PR_DestroyRWLock(mRwLock);
00073    }
00074 
00081    vpr::ReturnStatus acquire()
00082    {
00083       return acquireWrite();
00084    }
00085 
00089    vpr::ReturnStatus acquireRead()
00090    {
00091       PR_RWLock_Rlock(mRwLock);
00092       return vpr::ReturnStatus();
00093    }
00094 
00098    vpr::ReturnStatus acquireWrite()
00099    {
00100       PR_RWLock_Wlock(mRwLock);
00101       return vpr::ReturnStatus();
00102    }
00103 
00114    vpr::ReturnStatus tryAcquire()
00115    {
00116       return tryAcquireWrite();
00117    }
00118 
00122    vpr::ReturnStatus tryAcquireRead();
00123 
00127    vpr::ReturnStatus tryAcquireWrite();
00128 
00135    vpr::ReturnStatus release()
00136    {
00137       PR_RWLock_Unlock(mRwLock);
00138       return vpr::ReturnStatus();
00139    }
00140 
00147 /*
00148     int test()
00149     {
00150         return stateLock.test();
00151     }
00152 */
00153 
00154 protected:
00155    int numWaitingReaders;    
00156    int numWaitingWriters;    
00162    int mRefCount;
00163 
00164    PRRWLock* mRwLock;
00165 
00166    // = Prevent assignment and initialization.
00167    void operator= (const RWMutexNSPR &)
00168    {
00169       /* Do nothing. */ ;
00170    }
00171 
00172    RWMutexNSPR(const RWMutexNSPR &)
00173    {
00174       /* Do nothing. */ ;
00175    }
00176 };
00177 
00178 } // End of vpr namespace
00179 
00180 
00181 #endif  /* _VPR_RW_MUTEX_NSPR_H_ */

Generated on Thu Jan 4 10:52:10 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1