Skip to content

Commit

Permalink
Fixed|libcore: Stopping the Timer thread
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 3cbfe94 commit 556a340
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions doomsday/libs/core/src/core/timer.cpp
Expand Up @@ -138,6 +138,17 @@ struct TimerScheduler : public Thread, public Lockable

static LockableT<TimerScheduler *> scheduler;
static std::atomic_int timerCount; // Number of timers in existence.

static void deleteTimerScheduler()
{
DE_GUARD(scheduler);
if (scheduler.value)
{
scheduler.value->stop();
delete scheduler.value;
scheduler.value = nullptr;
}
}

} // namespace internal

Expand All @@ -148,19 +159,19 @@ DE_PIMPL_NOREF(Timer)
bool isActive = false;
std::atomic_bool isPending{false}; // posted but not executed yet

~Impl()
{
using namespace internal;

// The timer scheduler thread is stopped after all timers have been deleted.
DE_GUARD(scheduler);
if (--timerCount == 0)
{
scheduler.value->stop();
delete scheduler.value;
scheduler.value = nullptr;
}
}
// ~Impl()
// {
// using namespace internal;
//
// // The timer scheduler thread is stopped after all timers have been deleted.
// DE_GUARD(scheduler);
// if (--timerCount == 0)
// {
// scheduler.value->stop();
// delete scheduler.value;
// scheduler.value = nullptr;
// }
// }

DE_PIMPL_AUDIENCE(Trigger)
};
Expand All @@ -177,6 +188,7 @@ Timer::Timer()
{
scheduler.value = new TimerScheduler;
scheduler.value->start();
atexit(deleteTimerScheduler);
}
++timerCount;
}
Expand Down

0 comments on commit 556a340

Please sign in to comment.