Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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
28////////////////////////////////////////////////////////////////////////////////
29/// Create a Win32 mutex lock.
30
32{
33 ::InitializeCriticalSection(&fCritSect);
34}
35
36////////////////////////////////////////////////////////////////////////////////
37/// TMutex dtor.
38
40{
41 ::DeleteCriticalSection(&fCritSect);
42}
43
44////////////////////////////////////////////////////////////////////////////////
45/// Lock the mutex.
46
48{
49 ::EnterCriticalSection(&fCritSect);
50 return 0;
51}
52
53////////////////////////////////////////////////////////////////////////////////
54/// Try locking the mutex. Returns 0 if mutex can be locked.
55
57{
58 if (::TryEnterCriticalSection(&fCritSect))
59 return 0;
60 return 1;
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Unlock the mutex.
65
67{
68 ::LeaveCriticalSection(&fCritSect);
69 return 0;
70}
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
Int_t Lock() override
Lock the mutex.
Int_t UnLock() override
Unlock the mutex.
virtual ~TWin32Mutex()
TMutex dtor.
TWin32Mutex(Bool_t recursive=kFALSE)
Create a Win32 mutex lock.
Int_t TryLock() override
Try locking the mutex. Returns 0 if mutex can be locked.
CRITICAL_SECTION fCritSect
Definition TWin32Mutex.h:33