Integration of OCCT 6.5.0 from SVN
[occt.git] / src / Standard / Standard_Mutex.cxx
1 // File:        Standard_Mutex.cxx
2 // Created:     Thu Apr 13 08:21:40 2006
3 // Author:      Andrey BETENEV
4 // Copyright:   Open CASCADE S.A.S. 2006
5
6 // On Windows, function TryEnterCriticalSection has appeared in Windows NT
7 // and is surrounded by #ifdef in MS VC++ 7.1 headers.
8 // Thus to use it we need to define appropriate macro saying that we wil
9 // run on Windows NT 4.0 at least
10 #if defined(WNT) && ! defined(_WIN32_WINNT)
11 #define _WIN32_WINNT 0x0400
12 #endif
13
14 #include <Standard_Mutex.hxx>
15 #include <Standard_OStream.hxx>
16
17 //=============================================
18 // Standard_Mutex::Standard_Mutex
19 //=============================================
20
21 Standard_Mutex::Standard_Mutex () 
22 {
23 #ifdef WNT
24   InitializeCriticalSection( &myMutex );
25 #else
26   pthread_mutex_init( &myMutex, 0 );
27 #endif
28 }
29
30 //=============================================
31 // Standard_Mutex::~Standard_Mutex
32 //=============================================
33
34 Standard_Mutex::~Standard_Mutex () 
35 {
36 #ifdef WNT
37   DeleteCriticalSection( &myMutex );
38 #else
39   pthread_mutex_destroy( &myMutex );
40 #endif
41 }
42
43 //=============================================
44 // Standard_Mutex::Lock
45 //=============================================
46
47 void Standard_Mutex::Lock ()
48 {
49 #ifdef WNT
50   EnterCriticalSection( &myMutex );
51 #else
52   pthread_mutex_lock( &myMutex );
53 #endif
54 }
55
56 //=============================================
57 // Standard_Mutex::TryLock
58 //=============================================
59
60 Standard_Boolean Standard_Mutex::TryLock ()
61 {
62 #ifdef WNT
63   return ( TryEnterCriticalSection( &myMutex ) != 0 );
64 #else
65   return ( pthread_mutex_trylock( &myMutex ) != EBUSY );
66 #endif
67 }
68
69 //=============================================
70 // Standard_Mutex::DestroyCallback
71 //=============================================
72
73 void Standard_Mutex::DestroyCallback ()
74 {
75   UnregisterCallback();
76   Unlock();
77 }