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();
}
ASSERT(m_state.value() == 0);
m_alive = 1;
+ m_started = 0;
/* start thread. */
pthread_attr_t attr;
pthread_attr_setschedpolicy(&attr, policy);
pthread_attr_setschedparam(&attr, &p);
}
-
+
+ if (the_thread) {
+ eDebug("old thread joined %d", pthread_join(the_thread, 0));
+ the_thread = 0;
+ }
+
if (pthread_create(&the_thread, &attr, wrapper, this))
{
pthread_attr_destroy(&attr);
pthread_attr_destroy(&attr);
return 0;
-}
+}
int eThread::run(int prio, int policy)
{
void eThread::hasStarted()
{
ASSERT(!m_state.value());
+ m_started = 1;
m_state.up();
}