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
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
14 #include <Standard_Mutex.hxx>
15 #include <Standard_OStream.hxx>
17 //=============================================
18 // Standard_Mutex::Standard_Mutex
19 //=============================================
21 Standard_Mutex::Standard_Mutex ()
24 InitializeCriticalSection( &myMutex );
26 pthread_mutex_init( &myMutex, 0 );
30 //=============================================
31 // Standard_Mutex::~Standard_Mutex
32 //=============================================
34 Standard_Mutex::~Standard_Mutex ()
37 DeleteCriticalSection( &myMutex );
39 pthread_mutex_destroy( &myMutex );
43 //=============================================
44 // Standard_Mutex::Lock
45 //=============================================
47 void Standard_Mutex::Lock ()
50 EnterCriticalSection( &myMutex );
52 pthread_mutex_lock( &myMutex );
56 //=============================================
57 // Standard_Mutex::TryLock
58 //=============================================
60 Standard_Boolean Standard_Mutex::TryLock ()
63 return ( TryEnterCriticalSection( &myMutex ) != 0 );
65 return ( pthread_mutex_trylock( &myMutex ) != EBUSY );
69 //=============================================
70 // Standard_Mutex::DestroyCallback
71 //=============================================
73 void Standard_Mutex::DestroyCallback ()