Skip to content

Commit

Permalink
liblegacy|Debug: More robust threading behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 22c9bed commit 05c39c0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions doomsday/libs/legacy/src/concurrency.cpp
Expand Up @@ -49,6 +49,7 @@ CallbackThread::~CallbackThread()
{
if (isRunning())
{
DE_ASSERT(!isCurrentThread());
de::debug("CallbackThread %p being forcibly stopped before deletion", this);
terminate();
// wait(1000);
Expand All @@ -62,7 +63,10 @@ CallbackThread::~CallbackThread()
void CallbackThread::threadFinished(Thread &)
{
using namespace de;
Loop::mainCall([this]() { trash(this); });
Loop::mainCall([this]() {
DE_ASSERT(!isCurrentThread());
trash(this);
});
}

void CallbackThread::run()
Expand Down Expand Up @@ -169,7 +173,7 @@ int Sys_WaitThread(thread_t handle, int timeoutMs, systhreadexitstatus_t *exitSt
}

CallbackThread *t = reinterpret_cast<CallbackThread *>(handle);
DE_ASSERT(static_cast<de::Thread *>(t) != de::Thread::currentThread());
DE_ASSERT(!t->isCurrentThread());
t->wait(de::TimeSpan::fromMilliSeconds(timeoutMs));
if (!t->isFinished())
{
Expand All @@ -180,8 +184,6 @@ int Sys_WaitThread(thread_t handle, int timeoutMs, systhreadexitstatus_t *exitSt
{
if (exitStatus) *exitStatus = t->exitStatus();
}
//t->deleteLater(); // get rid of it
de::trash(t);
return t->exitValue();
}

Expand Down

0 comments on commit 05c39c0

Please sign in to comment.