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>
27 //=============================================
28 // Standard_Mutex::Standard_Mutex
29 //=============================================
31 Standard_Mutex::Standard_Mutex ()
33 #if (defined(_WIN32) || defined(__WIN32__))
34 InitializeCriticalSection (&myMutex);
36 pthread_mutexattr_t anAttr;
37 pthread_mutexattr_init (&anAttr);
38 pthread_mutexattr_settype (&anAttr, PTHREAD_MUTEX_RECURSIVE);
39 pthread_mutex_init (&myMutex, &anAttr);
40 pthread_mutexattr_destroy (&anAttr);
44 //=============================================
45 // Standard_Mutex::~Standard_Mutex
46 //=============================================
48 Standard_Mutex::~Standard_Mutex ()
50 #if (defined(_WIN32) || defined(__WIN32__))
51 DeleteCriticalSection (&myMutex);
53 pthread_mutex_destroy (&myMutex);
57 //=============================================
58 // Standard_Mutex::Lock
59 //=============================================
61 void Standard_Mutex::Lock ()
63 #if (defined(_WIN32) || defined(__WIN32__))
64 EnterCriticalSection (&myMutex);
66 pthread_mutex_lock (&myMutex);
70 //=============================================
71 // Standard_Mutex::TryLock
72 //=============================================
74 Standard_Boolean Standard_Mutex::TryLock ()
76 #if (defined(_WIN32) || defined(__WIN32__))
77 return (TryEnterCriticalSection (&myMutex) != 0);
79 return (pthread_mutex_trylock (&myMutex) != EBUSY);
83 //=============================================
84 // Standard_Mutex::DestroyCallback
85 //=============================================
87 void Standard_Mutex::DestroyCallback ()