X-Git-Url: http://code.vuplus.com/gitweb/?a=blobdiff_plain;f=lib%2Fbase%2Fthread.cpp;h=fa923debe3ddf08aed24ec059b663a1b7486e071;hb=d4a487ead0f0a70be38632e8a094e87c06daf903;hp=db6deb3585023c8a5fd0b6900af1177d19d326ad;hpb=62a59db2e74147b3b8edeeefbf0ebb64afe0311c;p=vuplus_dvbapp diff --git a/lib/base/thread.cpp b/lib/base/thread.cpp index db6deb3..fa923de 100644 --- a/lib/base/thread.cpp +++ b/lib/base/thread.cpp @@ -9,12 +9,9 @@ void eThread::thread_completed(void *ptr) eThread *p = (eThread*) ptr; p->m_alive = 0; - /* recover state */ - if (!p->m_state.value()) - { - p->m_state.up(); - ASSERT(p->m_state.value() == 1); - } + /* recover state in case thread was cancelled before calling hasStarted */ + if (!p->m_started) + p->hasStarted(); p->thread_finished(); } @@ -45,8 +42,10 @@ int eThread::runAsync(int prio, int policy) ASSERT(m_state.value() == 1); /* sync postconditions */ ASSERT(!m_alive); m_state.down(); + ASSERT(m_state.value() == 0); m_alive = 1; + m_started = 0; /* start thread. */ pthread_attr_t attr; @@ -88,8 +87,11 @@ eThread::~eThread() int eThread::sync(void) { int res; + int debug_val_before = m_state.value(); m_state.down(); /* this might block */ res = m_alive; + if (m_state.value() != 0) + eFatal("eThread::sync: m_state.value() == %d - was %d before", m_state.value(), debug_val_before); ASSERT(m_state.value() == 0); m_state.up(); return res; /* 0: thread is guaranteed not to run. 1: state unknown. */ @@ -121,5 +123,6 @@ void eThread::kill(bool sendcancel) void eThread::hasStarted() { ASSERT(!m_state.value()); + m_started = 1; m_state.up(); }