Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/nto/bakJuly/RWLock.hpp

Go to the documentation of this file.
00001 #ifndef __J2K__RWLock_HPP__
00002 #define __J2K__RWLock_HPP__
00003 
00004 #include <j2k/Fred/Standard.hpp>
00005 #include <j2k/nto/Mutex.hpp>
00006 
00007 //
00008 // Classical Implementation of Reader/Writer lock using Mutex
00009 // Don't use pthread_rwlock, since it's not implemented on every platforms;
00010 // however, pthread_mutex is more common than pthread_rwlock, 
00011 // so use it to implement the other.
00012 //
00013 // It's also simpler to code then to play with C structs...
00014 //
00015 // Use your Comp346 book as a reference for the pseudo-code.
00016 //
00017 
00018 class RWLock {
00019 public:
00020  inline RWLock();
00021  inline virtual ~RWLock();
00022 
00023  void read();
00024  void write();
00025 
00026  void releaseRead();
00027  void releaseWrite();
00028 
00029 private:
00030  // -1  = writing
00031  //  0  = NotUsed (Available)
00032  //  1+ = reading
00033 
00034  long  readers;
00035 
00036  int   readfail;
00037  int   writefail;
00038  int   loop;
00039 
00040  Mutex mutex;
00041 
00042 
00043 // Not implemented or needed.
00044 private:
00045   // Copy constructor
00046   inline RWLock( const RWLock& src );
00047 
00048   // Assign operator
00049   inline const RWLock& operator=( const RWLock& src );
00050 };
00051 
00052 #include <j2k/nto/RWLock.inl>
00053 
00054 #endif

Generated on Sun Oct 14 18:46:24 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001