Skip to content

Commit

Permalink
workaround for sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
plugz committed Dec 15, 2014
1 parent c6f9888 commit 11705ee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
12 changes: 11 additions & 1 deletion engine/src/function.cpp
Expand Up @@ -82,6 +82,7 @@ Function::Function(Doc* doc, Type t)
, m_flashing(false)
, m_elapsed(0)
, m_stop(true)
, m_stopping(false)
, m_running(false)
, m_startedAsChild(false)
{
Expand Down Expand Up @@ -749,6 +750,7 @@ void Function::preRun(MasterTimer* timer)

qDebug() << "Function preRun. Name:" << m_name << "ID: " << m_id;
m_running = true;
m_stop = false;

emit running(m_id);
}
Expand All @@ -763,6 +765,7 @@ void Function::postRun(MasterTimer* timer, QList<Universe *> universes)
resetElapsed();
resetAttributes();
m_stop = true;
m_stopping = false;
//m_overrideFadeInSpeed = defaultSpeed();
//m_overrideFadeOutSpeed = defaultSpeed();
//m_overrideDuration = defaultSpeed();
Expand Down Expand Up @@ -814,7 +817,7 @@ void Function::start(MasterTimer* timer, bool child, quint32 startTime,
m_overrideFadeInSpeed = overrideFadeIn;
m_overrideFadeOutSpeed = overrideFadeOut;
m_overrideDuration = overrideDuration;
m_stop = false;
m_stopping = false;
timer->startFunction(this);
}

Expand All @@ -827,19 +830,26 @@ void Function::stop()
{
qDebug() << "Function stop(). Name:" << m_name << "ID: " << m_id;
m_stop = true;
m_stopping = true;
}

bool Function::stopped() const
{
return m_stop;
}

bool Function::stopping() const
{
return m_stopping || m_stop;
}

bool Function::stopAndWait()
{
bool result = true;

m_stopMutex.lock();
m_stop = true;
m_stopping = true;

QTime watchdog;
watchdog.start();
Expand Down
10 changes: 8 additions & 2 deletions engine/src/function.h
Expand Up @@ -619,13 +619,18 @@ public slots:
void stop();

/**
* Check, whether the function should be stopped ASAP. Functions can use this
* to check, whether they should continue running or bail out.
* Check, whether the function is stopped or going to be stopped after the
* next tick to check, whether they should continue running or bail out.
*
* @return true if the function should be stopped, otherwise false.
*/
bool stopped() const;

/**
* Check wether this function has to be stopped after the next tick.
*/
bool stopping() const;

/**
* Mark the function to be stopped and block the calling thread until it is
* actually stopped. To prevent deadlocks the function only waits for 2s.
Expand All @@ -646,6 +651,7 @@ public slots:
private:
/** Stop flag, private to keep functions from modifying it. */
bool m_stop;
bool m_stopping;
bool m_running;

QMutex m_stopMutex;
Expand Down
2 changes: 1 addition & 1 deletion engine/src/mastertimer.cpp
Expand Up @@ -227,7 +227,7 @@ void MasterTimer::timerTickFunctions(QList<Universe *> universes)
if (function != NULL)
{
/* Run the function unless it's supposed to be stopped */
if (function->stopped() == false && m_stopAllFunctions == false)
if (function->stopping() == false && m_stopAllFunctions == false)
{
function->write(this, universes);
}
Expand Down

0 comments on commit 11705ee

Please sign in to comment.