Make ProgressSentry thread safe. It will update indicator only when it is executed in the thread where it was created.
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 );
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 );
#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;
Handle(Message_ProgressIndicator) myProgress;
Standard_Boolean myActive;
+ Standard_ThreadId myThreadId;
};
inline void Message_ProgressSentry::Relieve ()
{
- if ( ! myActive ) return;
+ if (!myActive || myThreadId != OSD_Thread::Current()) return;
myProgress->EndScope();
myActive = 0;
}
inline void Message_ProgressSentry::Next (const Standard_CString name) const
{
- if ( myActive ) myProgress->NextScope(name);
+ if (myActive && myThreadId == OSD_Thread::Current())
+ myProgress->NextScope(name);
}
//=======================================================================
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);
}
//=======================================================================
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);
}
inline void Message_ProgressSentry::Show () const
{
- if ( ! myProgress.IsNull() ) myProgress->Show();
+ if (!myProgress.IsNull() && myThreadId == OSD_Thread::Current())
+ myProgress->Show();
}