Logo ROOT   6.08/07
Reference Guide
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 
28 
29 ////////////////////////////////////////////////////////////////////////////////
30 /// Create a Win32 mutex lock.
31 
33 {
34  ::InitializeCriticalSection(&fCritSect);
35 }
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// TMutex dtor.
39 
41 {
42  ::DeleteCriticalSection(&fCritSect);
43 }
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// Lock the mutex.
47 
49 {
50  ::EnterCriticalSection(&fCritSect);
51  return 0;
52 }
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 /// Try locking the mutex. Returns 0 if mutex can be locked.
56 
58 {
59  if (::TryEnterCriticalSection(&fCritSect))
60  return 0;
61  return 1;
62 }
63 
64 ////////////////////////////////////////////////////////////////////////////////
65 /// Unlock the mutex.
66 
68 {
69  ::LeaveCriticalSection(&fCritSect);
70  return 0;
71 }
Int_t UnLock()
Unlock the mutex.
Definition: TWin32Mutex.cxx:67
Int_t Lock()
Lock the mutex.
Definition: TWin32Mutex.cxx:48
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
CRITICAL_SECTION fCritSect
Definition: TWin32Mutex.h:39
Int_t TryLock()
Try locking the mutex. Returns 0 if mutex can be locked.
Definition: TWin32Mutex.cxx:57
#define ClassImp(name)
Definition: Rtypes.h:279
virtual ~TWin32Mutex()
TMutex dtor.
Definition: TWin32Mutex.cxx:40