00001 // @(#)root/thread:$Id: TWin32Condition.h 20882 2007-11-19 11:31:26Z rdm $ 00002 // Author: Bertrand Bellenot 20/10/2004 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2004, 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_TWin32Condition 00013 #define ROOT_TWin32Condition 00014 00015 00016 ////////////////////////////////////////////////////////////////////////// 00017 // // 00018 // TWin32Condition // 00019 // // 00020 // This class provides an interface to the win32 condition variable // 00021 // routines. // 00022 // // 00023 ////////////////////////////////////////////////////////////////////////// 00024 00025 #ifndef ROOT_TConditionImp 00026 #include "TConditionImp.h" 00027 #endif 00028 00029 #include "Windows4Root.h" 00030 00031 #ifndef __CINT__ 00032 typedef struct 00033 { 00034 int waiters_count_; 00035 // Number of waiting threads. 00036 00037 CRITICAL_SECTION waiters_count_lock_; 00038 // Serialize access to <waiters_count_>. 00039 00040 HANDLE sema_; 00041 // Semaphore used to queue up threads waiting for the condition to 00042 // become signaled. 00043 00044 HANDLE waiters_done_; 00045 // An auto-reset event used by the broadcast/signal thread to wait 00046 // for all the waiting thread(s) to wake up and be released from the 00047 // semaphore. 00048 00049 size_t was_broadcast_; 00050 // Keeps track of whether we were broadcasting or signaling. This 00051 // allows us to optimize the code if we're just signaling. 00052 } pthread_cond_t; 00053 #else 00054 struct pthread_cond_t; 00055 #endif 00056 00057 class TMutexImp; 00058 class TWin32Mutex; 00059 00060 00061 class TWin32Condition : public TConditionImp { 00062 00063 private: 00064 pthread_cond_t fCond; // the pthread condition variable 00065 TWin32Mutex *fMutex; // mutex used around Wait() and TimedWait() 00066 00067 public: 00068 TWin32Condition(TMutexImp *m); 00069 virtual ~TWin32Condition(); 00070 00071 Int_t Wait(); 00072 Int_t TimedWait(ULong_t secs, ULong_t nanoSecs = 0); 00073 Int_t Signal(); 00074 Int_t Broadcast(); 00075 00076 ClassDef(TWin32Condition,0) // Posix condition variable 00077 }; 00078 00079 #endif