00001 // @(#)root/thread:$Id: TSemaphore.h 20882 2007-11-19 11:31:26Z rdm $ 00002 // Author: Fons Rademakers 02/07/97 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 #ifndef ROOT_TSemaphore 00013 #define ROOT_TSemaphore 00014 00015 00016 ////////////////////////////////////////////////////////////////////////// 00017 // // 00018 // TSemaphore // 00019 // // 00020 // This class implements a counting semaphore. Use a semaphore // 00021 // to synchronize threads. // 00022 // // 00023 ////////////////////////////////////////////////////////////////////////// 00024 00025 #ifndef ROOT_TObject 00026 #include "TObject.h" 00027 #endif 00028 #ifndef ROOT_TMutex 00029 #include "TMutex.h" 00030 #endif 00031 #ifndef ROOT_TCondition 00032 #include "TCondition.h" 00033 #endif 00034 00035 00036 class TSemaphore : public TObject { 00037 00038 private: 00039 TMutex fMutex; // semaphare mutex 00040 TCondition fCond; // semaphore condition variable 00041 Int_t fValue; // counter 00042 00043 TSemaphore(const TSemaphore &s); // not implemented 00044 TSemaphore& operator=(const TSemaphore &s); // not implemented 00045 00046 public: 00047 TSemaphore(UInt_t initial = 1); 00048 virtual ~TSemaphore() { } 00049 00050 Int_t Wait(Int_t millisec = 0); 00051 Int_t TryWait(); 00052 Int_t Post(); 00053 00054 ClassDef(TSemaphore,0) // Counting semaphore class 00055 }; 00056 00057 #endif