1 // Created on: 2006-04-13
2 // Created by: Andrey BETENEV
3 // Copyright (c) 2006-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 // On Windows, function TryEnterCriticalSection has appeared in Windows NT
22 // and is surrounded by #ifdef in MS VC++ 7.1 headers.
23 // Thus to use it we need to define appropriate macro saying that we wil
24 // run on Windows NT 4.0 at least
25 #if defined(WNT) && ! defined(_WIN32_WINNT)
26 #define _WIN32_WINNT 0x0400
29 #include <Standard_Mutex.hxx>
30 #include <Standard_OStream.hxx>
32 //=============================================
33 // Standard_Mutex::Standard_Mutex
34 //=============================================
36 Standard_Mutex::Standard_Mutex ()
39 InitializeCriticalSection( &myMutex );
41 pthread_mutex_init( &myMutex, 0 );
45 //=============================================
46 // Standard_Mutex::~Standard_Mutex
47 //=============================================
49 Standard_Mutex::~Standard_Mutex ()
52 DeleteCriticalSection( &myMutex );
54 pthread_mutex_destroy( &myMutex );
58 //=============================================
59 // Standard_Mutex::Lock
60 //=============================================
62 void Standard_Mutex::Lock ()
65 EnterCriticalSection( &myMutex );
67 pthread_mutex_lock( &myMutex );
71 //=============================================
72 // Standard_Mutex::TryLock
73 //=============================================
75 Standard_Boolean Standard_Mutex::TryLock ()
78 return ( TryEnterCriticalSection( &myMutex ) != 0 );
80 return ( pthread_mutex_trylock( &myMutex ) != EBUSY );
84 //=============================================
85 // Standard_Mutex::DestroyCallback
86 //=============================================
88 void Standard_Mutex::DestroyCallback ()