From 62c535fff55c3495738ba27cd5167e12fa577f17 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sat, 21 Oct 2006 13:45:45 +0000 Subject: [PATCH] SILC_FSM_THREAD_WAIT continues to next state if already terminated. --- lib/silcutil/silcfsm.c | 8 +++++++- lib/silcutil/silcfsm.h | 9 ++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/silcutil/silcfsm.c b/lib/silcutil/silcfsm.c index 7a0bf4ac..c94425d0 100644 --- a/lib/silcutil/silcfsm.c +++ b/lib/silcutil/silcfsm.c @@ -318,12 +318,18 @@ void *silc_fsm_get_state_context(void *fsm) SilcBool silc_fsm_thread_wait(void *fsm, void *thread) { SilcFSM t = thread; + #if defined(SILC_DEBUG) assert(t->thread); #endif /* SILC_DEBUG */ + + if (t->finished) + return FALSE; t->u.t.sema = silc_fsm_sema_alloc(t->u.t.fsm, 0); if (!t->u.t.sema) return FALSE; + + SILC_LOG_DEBUG(("Waiting for thread %p to terminate", thread)); silc_fsm_sema_wait(t->u.t.sema, fsm); return TRUE; } @@ -649,7 +655,7 @@ static void silc_fsm_thread_termination_post(SilcFSMSema sema) SilcFSM fsm; SilcMutex lock = sema->fsm->u.m.lock; - SILC_LOG_DEBUG(("Post thread termination semaphore %p", sema)); + SILC_LOG_DEBUG(("Post thread terminate semaphore %p", sema)); silc_mutex_lock(lock); diff --git a/lib/silcutil/silcfsm.h b/lib/silcutil/silcfsm.h index 0eb707c8..8468c4fd 100644 --- a/lib/silcutil/silcfsm.h +++ b/lib/silcutil/silcfsm.h @@ -307,7 +307,9 @@ do { \ * * Macro used to wait for the `thread' to terminate. The machine or * thread will be suspended while it is waiting for the thread to - * terminate. + * terminate. If the thread to be waited has already terminated (but + * the context has not been freed yet), this will continue immediately + * to the following state without waiting. * * NOTES * @@ -325,8 +327,9 @@ do { \ ***/ #define SILC_FSM_THREAD_WAIT(thread) \ do { \ - silc_fsm_thread_wait(fsm, thread); \ - return SILC_FSM_WAIT; \ + if (silc_fsm_thread_wait(fsm, thread)) \ + return SILC_FSM_WAIT; \ + return SILC_FSM_CONTINUE; \ } while(0) /****f* silcutil/SilcFSMAPI/silc_fsm_alloc -- 2.24.0