![]() |
|
|
Bdb packages | Design docs | Source docs | Guidelines | Recent releases |
|
Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members /BdbCondRemote/BdbCondReadWriteLock.hh
Go to the documentation of this file.00001 //----------------------------------------------------------------------------- 00002 // 00003 // File and Version Information: 00004 // $Id: BdbCondReadWriteLock.hh,v 1.2 2000/07/17 21:44:34 gapon Exp $ 00005 // 00006 // Description: 00007 // This class represents a missing feature in the POSIX library - 00008 // "read/write lock" allowing to have either one WRITER or unlimited 00009 // number of READERs waiting for a resource to be released. 00010 // 00011 // Environment: 00012 // Software developed for the BaBar Detector at the SLAC B-Factory. 00013 // 00014 // Author List: 00015 // Igor A. Gaponenko Original Author 00016 // 00017 // Copyright Information: 00018 // Copyright (C) 2000 Lawrence Berkeley Laboratory 00019 // 00020 //----------------------------------------------------------------------------- 00021 00022 #ifndef BDBCONDREADWRITELOCK_HH 00023 #define BDBCONDREADWRITELOCK_HH 00024 00025 //----------------- 00026 // C/C++ Headers -- 00027 //----------------- 00028 00029 extern "C" { 00030 #include <pthread.h> 00031 } 00032 00033 // ------------------- 00034 // -- BaBar Headers -- 00035 // ------------------- 00036 00037 #include "BaBar/BaBar.hh" 00038 00039 //------------------------------- 00040 // Collaborating Class Headers -- 00041 //------------------------------- 00042 00043 // --------------------- 00044 // -- Class Interface -- 00045 // --------------------- 00046 00047 class BdbCondReadWriteLock { 00048 00049 public: 00050 00051 // Constructor(s). 00052 00053 BdbCondReadWriteLock( ); 00054 00055 // Destructor 00056 00057 virtual ~BdbCondReadWriteLock( ); 00058 00059 // Operations 00060 00061 /** The following operations may block the calling thread if the corresponding 00062 ** lock is not available: 00063 ** 00064 ** beginRead() 00065 ** beginWrite() 00066 ** 00067 ** The following operations do not block the calling thread but may unblock 00068 ** other threads waiting for the resource. 00069 ** 00070 ** endRead() 00071 ** downgrade() 00072 ** endWrite() 00073 ** 00074 ** The "false" return status of these operations means that something has failed 00075 ** during their execution. This means that the results of operation are unreliable. 00076 **/ 00077 00078 bool beginRead( ); 00079 bool endRead( ); 00080 00081 bool downgrade( ); 00082 00083 bool beginWrite( ); 00084 bool endWrite( ); 00085 00086 protected: 00087 00088 // The copy constructor and assignment operator are not available 00089 // to the end users because the semantics of these operations 00090 // is not defined yet. 00091 00092 BdbCondReadWriteLock( const BdbCondReadWriteLock& theLock ); 00093 00094 // Operators 00095 00096 BdbCondReadWriteLock& operator=( const BdbCondReadWriteLock& theLock ); 00097 00098 private: 00099 00100 // A mutex and a conditions variable regulating the synchronized behavior 00101 // of code accessing/modifying the counters. 00102 00103 pthread_mutex_t _myMutex; 00104 pthread_cond_t _myCondVar; 00105 00106 // The counters for the clients. 00107 00108 int _numReaders; // The current number of READERs. 00109 int _numWriters; // The current number of WRITERs. 00110 int _numPendings; // The current number of READERS and WRITERs waiting for 00111 // the lock to be released. 00112 }; 00113 00114 #endif /* BDBCONDREADWRITELOCK_HH */
BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us
Page Owner: Jacek Becla
Last Update: October 04, 2002