1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-06-20 11:54:07 +03:00
occt/src/Standard/Standard_Mutex.cxx
omy 49f38e37fc 0023286: Standard_Mutex behavior depends on platform
Implemented recursive POSIX mutex instead of non-recursive,
Removed SentryNested class, implemented it's features into Sentry class
Added second constructor to Sentry class
2012-11-23 15:38:27 +04:00

97 lines
3.0 KiB
C++
Executable File

// Created on: 2006-04-13
// Created by: Andrey BETENEV
// Copyright (c) 2006-2012 OPEN CASCADE SAS
//
// The content of this file is subject to the Open CASCADE Technology Public
// License Version 6.5 (the "License"). You may not use the content of this file
// except in compliance with the License. Please obtain a copy of the License
// at http://www.opencascade.org and read it completely before using this file.
//
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
//
// The Original Code and all software distributed under the License is
// distributed on an "AS IS" basis, without warranty of any kind, and the
// Initial Developer hereby disclaims all such warranties, including without
// limitation, any warranties of merchantability, fitness for a particular
// purpose or non-infringement. Please see the License for the specific terms
// and conditions governing the rights and limitations under the License.
// 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(_WIN32) || defined(__WIN32__)) && !defined(_WIN32_WINNT))
#define _WIN32_WINNT 0x0400
#endif
#include <Standard_Mutex.hxx>
#include <Standard_OStream.hxx>
//=============================================
// Standard_Mutex::Standard_Mutex
//=============================================
Standard_Mutex::Standard_Mutex ()
{
#if (defined(_WIN32) || defined(__WIN32__))
InitializeCriticalSection (&myMutex);
#else
pthread_mutexattr_t anAttr;
pthread_mutexattr_init (&anAttr);
pthread_mutexattr_settype (&anAttr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init (&myMutex, &anAttr);
pthread_mutexattr_destroy (&anAttr);
#endif
}
//=============================================
// Standard_Mutex::~Standard_Mutex
//=============================================
Standard_Mutex::~Standard_Mutex ()
{
#if (defined(_WIN32) || defined(__WIN32__))
DeleteCriticalSection (&myMutex);
#else
pthread_mutex_destroy (&myMutex);
#endif
}
//=============================================
// Standard_Mutex::Lock
//=============================================
void Standard_Mutex::Lock ()
{
#if (defined(_WIN32) || defined(__WIN32__))
EnterCriticalSection (&myMutex);
#else
pthread_mutex_lock (&myMutex);
#endif
}
//=============================================
// Standard_Mutex::TryLock
//=============================================
Standard_Boolean Standard_Mutex::TryLock ()
{
#if (defined(_WIN32) || defined(__WIN32__))
return (TryEnterCriticalSection (&myMutex) != 0);
#else
return (pthread_mutex_trylock (&myMutex) != EBUSY);
#endif
}
//=============================================
// Standard_Mutex::DestroyCallback
//=============================================
void Standard_Mutex::DestroyCallback ()
{
UnregisterCallback();
Unlock();
}