diff --git a/src/timed_thread.c b/src/timed_thread.c index ee223a65..c53a74f0 100644 --- a/src/timed_thread.c +++ b/src/timed_thread.c @@ -47,6 +47,7 @@ struct _timed_thread { struct timespec interval_time; /* interval_usecs as a struct timespec */ struct timespec wait_time; /* absolute future time next timed_thread_test will wait until */ int pipefd[2]; + int die; }; /* linked list of created threads */ @@ -156,6 +157,7 @@ void timed_thread_destroy(timed_thread *p_timed_thread, /* signal thread to stop */ pthread_mutex_lock(&p_timed_thread->runnable_mutex); pthread_cond_signal(&p_timed_thread->runnable_cond); + p_timed_thread->die = 1; pthread_mutex_unlock(&p_timed_thread->runnable_mutex); write(p_timed_thread->pipefd[1], "die", 3); @@ -209,6 +211,11 @@ int timed_thread_test(timed_thread *p_timed_thread, int override_wait_time) return -1; } + if (p_timed_thread->die) { + /* if we were kindly asked to die, then die */ + return 1; + } + if (override_wait_time && now(&p_timed_thread->wait_time)) { return -1; } diff --git a/src/timed_thread.h b/src/timed_thread.h index 8c0afe5c..38732c2e 100644 --- a/src/timed_thread.h +++ b/src/timed_thread.h @@ -46,7 +46,8 @@ int timed_thread_lock(timed_thread *p_timed_thread); int timed_thread_unlock(timed_thread *p_timed_thread); /* waits required interval (unless override_wait_time is non-zero) for - * termination signal returns 1 if received, 0 otherwise. */ + * termination signal returns 1 if received, 0 otherwise. should also return 1 + * if the thread has been asked kindly to die. */ int timed_thread_test(timed_thread *p_timed_thread, int override_wait_time); /* exit a timed thread */