Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TWin32Mutex.cxx
Go to the documentation of this file.
1 // @(#)root/thread:$Id$
2 // Author: Bertrand Bellenot 23/10/04
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TWin32Mutex //
15 // //
16 // This class provides an interface to the Win32 mutex routines. //
17 // //
18 //////////////////////////////////////////////////////////////////////////
19 
20 #ifndef _WIN32_WINNT
21 #define _WIN32_WINNT 0x0501 // needed for TryEnterCriticalSection
22 #endif
23 
24 #include "TThread.h"
25 #include "TWin32Mutex.h"
26 
27 ClassImp(TWin32Mutex);
28 
29 ////////////////////////////////////////////////////////////////////////////////
30 /// Create a Win32 mutex lock.
31 
32 TWin32Mutex::TWin32Mutex(Bool_t recursive) : TMutexImp()
33 {
34  ::InitializeCriticalSection(&fCritSect);
35 }
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// TMutex dtor.
39 
40 TWin32Mutex::~TWin32Mutex()
41 {
42  ::DeleteCriticalSection(&fCritSect);
43 }
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// Lock the mutex.
47 
48 Int_t TWin32Mutex::Lock()
49 {
50  ::EnterCriticalSection(&fCritSect);
51  return 0;
52 }
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 /// Try locking the mutex. Returns 0 if mutex can be locked.
56 
57 Int_t TWin32Mutex::TryLock()
58 {
59  if (::TryEnterCriticalSection(&fCritSect))
60  return 0;
61  return 1;
62 }
63 
64 ////////////////////////////////////////////////////////////////////////////////
65 /// Unlock the mutex.
66 
67 Int_t TWin32Mutex::UnLock(void)
68 {
69  ::LeaveCriticalSection(&fCritSect);
70  return 0;
71 }