mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-03 17:56:21 +03:00
0033658: Foundation Classes - Move Standard_Mutex on STL base
Reorganize Standard_Mutex to use recursive_mutex Now we can see much more dead-lock cases Optimize progress indicator
This commit is contained in:
parent
983e35ed71
commit
58a48b4ac1
@ -65,6 +65,11 @@ public:
|
||||
//! Clears/erases opened TCL windows if any
|
||||
//! and sets myBreak to False
|
||||
Standard_EXPORT virtual void Reset() Standard_OVERRIDE;
|
||||
|
||||
Standard_Boolean IsActive() const Standard_OVERRIDE
|
||||
{
|
||||
return myGraphMode || myTclMode || myConsoleMode;
|
||||
}
|
||||
|
||||
//! Defines method Show of Progress Indicator
|
||||
Standard_EXPORT virtual void Show (const Message_ProgressScope& theScope,
|
||||
|
@ -48,6 +48,7 @@ Message_ProgressRange Message_ProgressIndicator::Start()
|
||||
myRootScope->myValue = 0.;
|
||||
Reset();
|
||||
Show (*myRootScope, Standard_False);
|
||||
myRootScope->myIsActive = IsActive();
|
||||
return myRootScope->Next();
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,8 @@ public:
|
||||
//! Use this method to get the top level range for progress indication.
|
||||
Standard_EXPORT Message_ProgressRange Start();
|
||||
|
||||
virtual Standard_Boolean IsActive() const { return true; }
|
||||
|
||||
//! If argument is non-null handle, returns theProgress->Start().
|
||||
//! Otherwise, returns dummy range that can be safely used in the algorithms
|
||||
//! but not bound to progress indicator.
|
||||
|
@ -15,62 +15,6 @@
|
||||
|
||||
#include <Standard_Mutex.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
|
||||
//=============================================
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#include <mutex>
|
||||
|
||||
/**
|
||||
* @brief Mutex: a class to synchronize access to shared data.
|
||||
*
|
||||
@ -122,9 +124,9 @@ public:
|
||||
}
|
||||
|
||||
//! This method should not be called (prohibited).
|
||||
Sentry (const Sentry &);
|
||||
Sentry (const Sentry &) = delete;
|
||||
//! This method should not be called (prohibited).
|
||||
Sentry& operator = (const Sentry &);
|
||||
Sentry& operator = (const Sentry &) = delete;
|
||||
|
||||
private:
|
||||
Standard_Mutex* myMutex;
|
||||
@ -135,22 +137,22 @@ public:
|
||||
//! Constructor: creates a mutex object and initializes it.
|
||||
//! It is strongly recommended that mutexes were created as
|
||||
//! static objects whenever possible.
|
||||
Standard_EXPORT Standard_Mutex ();
|
||||
Standard_Mutex() {};
|
||||
|
||||
//! Destructor: destroys the mutex object
|
||||
Standard_EXPORT ~Standard_Mutex ();
|
||||
~Standard_Mutex() {};
|
||||
|
||||
//! Method to lock the mutex; waits until the mutex is released
|
||||
//! by other threads, locks it and then returns
|
||||
Standard_EXPORT void Lock ();
|
||||
void Lock() { myMutex.lock(); }
|
||||
|
||||
//! Method to test the mutex; if the mutex is not hold by other thread,
|
||||
//! locks it and returns True; otherwise returns False without waiting
|
||||
//! mutex to be released.
|
||||
Standard_EXPORT Standard_Boolean TryLock ();
|
||||
Standard_Boolean TryLock () { return myMutex.try_lock(); }
|
||||
|
||||
//! Method to unlock the mutex; releases it to other users
|
||||
void Unlock ();
|
||||
void Unlock() { myMutex.unlock(); }
|
||||
|
||||
private:
|
||||
|
||||
@ -158,29 +160,14 @@ private:
|
||||
Standard_EXPORT virtual void DestroyCallback() Standard_OVERRIDE;
|
||||
|
||||
//! This method should not be called (prohibited).
|
||||
Standard_Mutex (const Standard_Mutex &);
|
||||
Standard_Mutex (const Standard_Mutex &) = delete;
|
||||
//! This method should not be called (prohibited).
|
||||
Standard_Mutex& operator = (const Standard_Mutex &);
|
||||
Standard_Mutex& operator = (const Standard_Mutex &) = delete;
|
||||
|
||||
private:
|
||||
#if (defined(_WIN32) || defined(__WIN32__))
|
||||
CRITICAL_SECTION myMutex;
|
||||
#else
|
||||
pthread_mutex_t myMutex;
|
||||
#endif
|
||||
std::recursive_mutex myMutex;
|
||||
};
|
||||
|
||||
typedef NCollection_Shared<Standard_Mutex> Standard_HMutex;
|
||||
|
||||
// Implementation of the method Unlock is inline, since it is
|
||||
// just a shortcut to system function
|
||||
inline void Standard_Mutex::Unlock ()
|
||||
{
|
||||
#if (defined(_WIN32) || defined(__WIN32__))
|
||||
LeaveCriticalSection (&myMutex);
|
||||
#else
|
||||
pthread_mutex_unlock (&myMutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* _Standard_Mutex_HeaderFile */
|
||||
|
Loading…
x
Reference in New Issue
Block a user