]> OCCT Git - occt.git/commitdiff
0033658: Foundation Classes - Move Standard_Mutex on STL base CR33658
authordpasukhi <dpasukhi@opencascade.com>
Tue, 12 Mar 2024 13:49:21 +0000 (13:49 +0000)
committerdpasukhi <dpasukhi@opencascade.com>
Fri, 29 Mar 2024 13:46:59 +0000 (13:46 +0000)
Reorganize Standard_Mutex to use recursive_mutex
Now we can see much more dead-lock cases
Optimize progress indicator

src/Draw/Draw_ProgressIndicator.hxx
src/Message/Message_ProgressIndicator.cxx
src/Message/Message_ProgressIndicator.hxx
src/Standard/Standard_Mutex.cxx
src/Standard/Standard_Mutex.hxx

index 393701fd86b7d0c3665c41987512a7f1f8f73d2f..965c3801ac727adc607c5ef1a751896997113742 100644 (file)
@@ -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, 
index 6abf893f9cb7c5c523d76d734d5c4e4d389dffc2..a745fbf9fee52749731ace7f0726b2ac25994ec6 100644 (file)
@@ -48,6 +48,7 @@ Message_ProgressRange Message_ProgressIndicator::Start()
   myRootScope->myValue = 0.;
   Reset();
   Show (*myRootScope, Standard_False);
+  myRootScope->myIsActive = IsActive();
   return myRootScope->Next();
 }
 
index ad6e5e547e12a3c6fa566af67d1e23bca9287d6b..1efadc78ef9d4bc9e51bbd9037be55e72f9bbd37 100644 (file)
@@ -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.
index 41090571dea1a969da5274f9cd5ed062b3330d47..7e067aa7db16b13d81e33cf7a746eed4862bd695 100644 (file)
 
 #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
 //=============================================
index 7197979d4ddf3a665b8e7addf7ddacf8cd6d81c9..c3758dad624a66459f019b33773d9aeff5f19391 100644 (file)
@@ -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 */