1 // Created on: 2006-04-13
2 // Created by: Andrey BETENEV
3 // Copyright (c) 2006-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // On Windows, function TryEnterCriticalSection has appeared in Windows NT
17 // and is surrounded by #ifdef in MS VC++ 7.1 headers.
18 // Thus to use it we need to define appropriate macro saying that we wil
19 // run on Windows NT 4.0 at least
20 #if ((defined(_WIN32) || defined(__WIN32__)) && !defined(_WIN32_WINNT))
21 #define _WIN32_WINNT 0x0400
24 #include <Standard_Mutex.hxx>
25 #include <Standard_OStream.hxx>
29 //=============================================
30 // Standard_Mutex::Standard_Mutex
31 //=============================================
33 Standard_Mutex::Standard_Mutex ()
35 #if (defined(_WIN32) || defined(__WIN32__))
36 InitializeCriticalSection (&myMutex);
38 pthread_mutexattr_t anAttr;
39 pthread_mutexattr_init (&anAttr);
40 pthread_mutexattr_settype (&anAttr, PTHREAD_MUTEX_RECURSIVE);
41 pthread_mutex_init (&myMutex, &anAttr);
42 pthread_mutexattr_destroy (&anAttr);
46 //=============================================
47 // Standard_Mutex::~Standard_Mutex
48 //=============================================
50 Standard_Mutex::~Standard_Mutex ()
52 #if (defined(_WIN32) || defined(__WIN32__))
53 DeleteCriticalSection (&myMutex);
55 pthread_mutex_destroy (&myMutex);
59 //=============================================
60 // Standard_Mutex::Lock
61 //=============================================
63 void Standard_Mutex::Lock ()
65 #if (defined(_WIN32) || defined(__WIN32__))
66 EnterCriticalSection (&myMutex);
68 pthread_mutex_lock (&myMutex);
72 //=============================================
73 // Standard_Mutex::TryLock
74 //=============================================
76 Standard_Boolean Standard_Mutex::TryLock ()
78 #if (defined(_WIN32) || defined(__WIN32__))
79 return (TryEnterCriticalSection (&myMutex) != 0);
81 return (pthread_mutex_trylock (&myMutex) != EBUSY);
85 //=============================================
86 // Standard_Mutex::DestroyCallback
87 //=============================================
89 void Standard_Mutex::DestroyCallback ()