]> OCCT Git - occt-copy.git/commitdiff
Temporary fix for 0029872: Express Mesh - instrument the algorithm with progress...
authormsv <msv@opencascade.com>
Mon, 25 Jun 2018 07:20:10 +0000 (10:20 +0300)
committermsv <msv@opencascade.com>
Fri, 4 Oct 2019 10:49:28 +0000 (13:49 +0300)
Make ProgressSentry thread safe. It will update indicator only when it is executed in the thread where it was created.

src/Message/Message_ProgressSentry.cxx
src/Message/Message_ProgressSentry.hxx
src/Message/Message_ProgressSentry.lxx

index 2648816f5b31c5358cbd4aa9a3632ffa174621a1..6110140468872dd7aa8a812c8279159f30f02b70 100644 (file)
@@ -27,7 +27,8 @@ Message_ProgressSentry::Message_ProgressSentry (const Handle(Message_ProgressInd
                                                   const Standard_Real step,
                                                   const Standard_Boolean isInf,
                                                   const Standard_Real newScopeSpan) :
-       myProgress(progress), myActive(!progress.IsNull())
+       myProgress(progress), myActive(!progress.IsNull()),
+       myThreadId(OSD_Thread::Current())
 {
   if ( ! myActive ) return;
   progress->SetName ( name );
@@ -47,7 +48,8 @@ Message_ProgressSentry::Message_ProgressSentry (const Handle(Message_ProgressInd
                                                   const Standard_Real step,
                                                   const Standard_Boolean isInf,
                                                   const Standard_Real newScopeSpan) :
-       myProgress(progress), myActive(!progress.IsNull())
+       myProgress(progress), myActive(!progress.IsNull()),
+       myThreadId(OSD_Thread::Current())
 {
   if ( ! myActive ) return;
   progress->SetName ( name );
index 0e7a094a5dcbc3ae0502ac1b8a0ba49df43ad728..1d34cf43d8c903b486b0c47a4aecd32169f4fb39 100644 (file)
@@ -23,6 +23,8 @@
 #include <Standard_Boolean.hxx>
 #include <Standard_CString.hxx>
 #include <Standard_Real.hxx>
+#include <Standard_ThreadId.hxx>
+#include <OSD_Thread.hxx>
 class Message_ProgressIndicator;
 class TCollection_HAsciiString;
 
@@ -109,6 +111,7 @@ private:
 
   Handle(Message_ProgressIndicator) myProgress;
   Standard_Boolean myActive;
+  Standard_ThreadId myThreadId;
 
 
 };
index e083a8ce46d999edc0e4982c5b997da3d3a6633e..03da604a931d76bc792a464c5d2332516e2fa146 100644 (file)
@@ -20,7 +20,7 @@
 
 inline void Message_ProgressSentry::Relieve ()
 {
-  if ( ! myActive ) return;
+  if (!myActive || myThreadId != OSD_Thread::Current()) return;
   myProgress->EndScope();
   myActive = 0;
 }
@@ -32,7 +32,8 @@ inline void Message_ProgressSentry::Relieve ()
 
 inline void Message_ProgressSentry::Next (const Standard_CString name) const
 {
-  if ( myActive ) myProgress->NextScope(name);
+  if (myActive && myThreadId == OSD_Thread::Current())
+    myProgress->NextScope(name);
 }
 
 //=======================================================================
@@ -43,7 +44,8 @@ inline void Message_ProgressSentry::Next (const Standard_CString name) const
 inline void Message_ProgressSentry::Next (const Standard_Real span, 
                                          const Standard_CString name) const
 {
-  if ( myActive ) myProgress->NextScope(span, name);
+  if (myActive && myThreadId == OSD_Thread::Current())
+    myProgress->NextScope(span, name);
 }
 
 //=======================================================================
@@ -54,7 +56,7 @@ inline void Message_ProgressSentry::Next (const Standard_Real span,
 inline void Message_ProgressSentry::Next (const Standard_Real span, 
                                          const Handle(TCollection_HAsciiString)& name) const
 {
-  if ( myActive ) {
+  if (myActive && myThreadId == OSD_Thread::Current()) {
     myProgress->EndScope();
     myProgress->NewScope(span, name);
   }
@@ -77,5 +79,6 @@ inline Standard_Boolean Message_ProgressSentry::More () const
 
 inline void Message_ProgressSentry::Show () const
 {
-  if ( ! myProgress.IsNull() ) myProgress->Show();
+  if (!myProgress.IsNull() && myThreadId == OSD_Thread::Current())
+    myProgress->Show();
 }