|
xrootd
|
00001 #ifndef __SYS_XSLOCK_HH__ 00002 #define __SYS_XSLOCK_HH__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d S y s X S L o c k . h h */ 00006 /* */ 00007 /* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC03-76-SFO0515 with the Department of Energy */ 00011 /******************************************************************************/ 00012 00013 // $Id$ 00014 00015 #include <errno.h> 00016 #include "XrdSys/XrdSysPthread.hh" 00017 00018 // These are valid usage options 00019 // 00020 enum XrdSysXS_Type {xs_None = 0, xs_Shared = 1, xs_Exclusive = 2}; 00021 00022 // This class implements the shared lock. Any number of readers are allowed 00023 // by requesting a shared lock. Only one exclusive writer is allowed by 00024 // requesting an exclusive lock. Up/downgrading is not supported. 00025 // 00026 class XrdSysXSLock 00027 { 00028 public: 00029 00030 void Lock(const XrdSysXS_Type usage); 00031 00032 void UnLock(const XrdSysXS_Type usage=xs_None); 00033 00034 XrdSysXSLock() : cur_usage(xs_None), cur_count(0), exc_wait(0), 00035 shr_wait(0), toggle(0), WantShr(0), WantExc(0) {} 00036 ~XrdSysXSLock(); 00037 00038 private: 00039 00040 XrdSysXS_Type cur_usage; 00041 int cur_count; 00042 int exc_wait; 00043 int shr_wait; 00044 int toggle; 00045 00046 XrdSysMutex LockContext; 00047 XrdSysSemaphore WantShr; 00048 XrdSysSemaphore WantExc; 00049 }; 00050 #endif
1.7.5