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