00001 // @(#)root/thread:$Id: TWin32Mutex.cxx 29797 2009-08-17 14:35:51Z rdm $ 00002 // Author: Bertrand Bellenot 23/10/04 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 ////////////////////////////////////////////////////////////////////////// 00013 // // 00014 // TWin32Mutex // 00015 // // 00016 // This class provides an interface to the Win32 mutex routines. // 00017 // // 00018 ////////////////////////////////////////////////////////////////////////// 00019 00020 #ifndef _WIN32_WINNT 00021 #define _WIN32_WINNT 0x0501 // needed for TryEnterCriticalSection 00022 #endif 00023 00024 #include "TThread.h" 00025 #include "TWin32Mutex.h" 00026 00027 ClassImp(TWin32Mutex) 00028 00029 //______________________________________________________________________________ 00030 TWin32Mutex::TWin32Mutex(Bool_t recursive) : TMutexImp() 00031 { 00032 // Create a Win32 mutex lock. 00033 00034 ::InitializeCriticalSection(&fCritSect); 00035 } 00036 00037 //______________________________________________________________________________ 00038 TWin32Mutex::~TWin32Mutex() 00039 { 00040 // TMutex dtor. 00041 00042 ::DeleteCriticalSection(&fCritSect); 00043 } 00044 00045 //______________________________________________________________________________ 00046 Int_t TWin32Mutex::Lock() 00047 { 00048 // Lock the mutex. 00049 00050 ::EnterCriticalSection(&fCritSect); 00051 return 0; 00052 } 00053 00054 //______________________________________________________________________________ 00055 Int_t TWin32Mutex::TryLock() 00056 { 00057 // Try locking the mutex. Returns 0 if mutex can be locked. 00058 00059 if (::TryEnterCriticalSection(&fCritSect)) 00060 return 0; 00061 return 1; 00062 } 00063 00064 //______________________________________________________________________________ 00065 Int_t TWin32Mutex::UnLock(void) 00066 { 00067 // Unlock the mutex. 00068 00069 ::LeaveCriticalSection(&fCritSect); 00070 return 0; 00071 }