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