Skip to content

Commit

Permalink
Fixed situation where it took long to pause tasks.
Browse files Browse the repository at this point in the history
  • Loading branch information
shoops committed Aug 5, 2021
1 parent c3a822e commit ac13c0c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 33 deletions.
67 changes: 36 additions & 31 deletions copasi/UI/CProgressBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,34 +176,6 @@ bool CProgressBar::progressItem(const size_t & handle)
if (!isValidHandle(handle) || mProgressItemList[handle] == NULL)
return false;

QDateTime currDateTime = QDateTime::currentDateTime();

if (mNextEventProcessing >= currDateTime)
return proceed();

mNextEventProcessing = currDateTime.addSecs(1);

if (mProccessingInstruction == ProccessingInstruction::Pause)
{
QMutexLocker Locker(&mMutex);
mWaitPause.wait(&mMutex);
}

if (!CopasiUI3Window::isMainThread())
{
if (mSlotFinished)
{
mSlotFinished = false;

emit signalProgressAll();
}
}
else
{
slotProgressAll();
QCoreApplication::processEvents();
}

return proceed();
}

Expand All @@ -222,6 +194,7 @@ void CProgressBar::slotProgressAll()
mSlotFinished = true;
}

// virtual
bool CProgressBar::finish()
{
// Assure that all signals have been properly handled before we delete
Expand Down Expand Up @@ -250,11 +223,9 @@ bool CProgressBar::finish()
}

CopasiUI3Window::getMainWindow()->disableSliders(false);

CProcessReport::finish();
done(1);

return proceed();
return CProcessReport::finish();
}

bool CProgressBar::finishItem(const size_t & handle)
Expand Down Expand Up @@ -305,6 +276,40 @@ void CProgressBar::slotFinishItem(const int handle)
mWaitSlot.wakeAll();
}

// virtual
bool CProgressBar::proceed()
{
if (mProccessingInstruction == ProccessingInstruction::Pause)
{
QMutexLocker Locker(&mMutex);
mWaitPause.wait(&mMutex);
}

QDateTime currDateTime = QDateTime::currentDateTime();

if (mNextEventProcessing < currDateTime)
{
mNextEventProcessing = currDateTime.addSecs(1);

if (!CopasiUI3Window::isMainThread())
{
if (mSlotFinished)
{
mSlotFinished = false;

emit signalProgressAll();
}
}
else
{
slotProgressAll();
QCoreApplication::processEvents();
}
}

return CProcessReport::proceed();
}

// virtual
bool CProgressBar::setName(const std::string & name)
{
Expand Down
9 changes: 9 additions & 0 deletions copasi/UI/CProgressBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ class CProgressBar : public CQProgressDialog, public CProcessReport
*/
virtual bool finishItem(const size_t & handle) override;

/**
* Check whether processing shall proceed. If the return value is false
* the calling process must halt execution and return. This method is
* provided so that lengthy processing without advances in any of the
* reporting items can check whether continuation is requested.
* @param bool continue
*/
virtual bool proceed() override;

/**
* Set the name of the process.
* @param const std::string & name
Expand Down
1 change: 0 additions & 1 deletion copasi/utilities/CProcessReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ bool CProcessReport::proceed()
return false;

return mProccessingInstruction == ProccessingInstruction::Continue
|| mProccessingInstruction == ProccessingInstruction::Pause
|| (mIgnoreStop && mProccessingInstruction == ProccessingInstruction::Stop);
}

Expand Down
2 changes: 1 addition & 1 deletion copasi/utilities/CProcessReport.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class CProcessReport
* reporting items can check whether continuation is requested.
* @param bool continue
*/
bool proceed();
virtual bool proceed();

/**
* Reset all item handle. This means that the values of the items have changed
Expand Down

0 comments on commit ac13c0c

Please sign in to comment.