From: Pekka Riikonen Date: Sat, 24 Jun 2006 19:39:19 +0000 (+0000) Subject: Removed silc_fsm_uninit -> not needed. X-Git-Tag: silc.client.1.1.beta1~310 X-Git-Url: http://git.silcnet.org/gitweb/?a=commitdiff_plain;h=f26bc2c10902a81955fe4b951c5679b42725eb00;p=silc.git Removed silc_fsm_uninit -> not needed. --- diff --git a/lib/silcutil/silcfsm.c b/lib/silcutil/silcfsm.c index dcefb09c..863516da 100644 --- a/lib/silcutil/silcfsm.c +++ b/lib/silcutil/silcfsm.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2005 Pekka Riikonen + Copyright (C) 2005 - 2006 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -137,6 +137,9 @@ SILC_TASK_CALLBACK(silc_fsm_free_final) SilcFSM f = context; #if defined(SILC_DEBUG) + /* We must be finished */ + assert(f->finished); + /* Machine must not have active threads */ if (!f->thread && f->u.m.threads) assert(f->u.m.threads == 0); @@ -159,35 +162,6 @@ void silc_fsm_free(void *fsm) silc_schedule_task_add_timeout(f->schedule, silc_fsm_free_final, f, 0, 1); } -/* FSM is uninitialized through scheduler to make sure that all dying - real system threads will have their finish callbacks scheduled before - this one (when SILC_FSM_THREAD_WAIT was used). */ - -SILC_TASK_CALLBACK(silc_fsm_uninit_final) -{ - SilcFSM f = context; - -#if defined(SILC_DEBUG) - /* Machine must not have active threads */ - if (!f->thread && f->u.m.threads) - assert(f->u.m.threads == 0); -#endif /* SILC_DEBUG */ - - if (!f->thread && f->u.m.lock) - silc_mutex_free(f->u.m.lock); - - if (f->thread && f->u.t.sema) - silc_fsm_sema_free(f->u.t.sema); -} - -/* Uninitializes FSM */ - -void silc_fsm_uninit(void *fsm) -{ - SilcFSM f = fsm; - silc_schedule_task_add_timeout(f->schedule, silc_fsm_uninit_final, f, 0, 1); -} - /* Task to start real thread. We start threads through scheduler, not directly in silc_fsm_start. */ @@ -433,6 +407,11 @@ SILC_TASK_CALLBACK(silc_fsm_finish) fsm->destructor(fsm, fsm->fsm_context, fsm->destructor_context); } else { + if (fsm->u.m.lock) { + silc_mutex_free(fsm->u.m.lock); + fsm->u.m.lock = NULL; + } + /* Call the destructor callback. */ if (fsm->destructor) fsm->destructor(fsm, fsm->fsm_context, fsm->destructor_context); diff --git a/lib/silcutil/silcfsm.h b/lib/silcutil/silcfsm.h index 72f11189..8822b2dd 100644 --- a/lib/silcutil/silcfsm.h +++ b/lib/silcutil/silcfsm.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2005 Pekka Riikonen + Copyright (C) 2005, 2006 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -67,7 +67,7 @@ typedef struct SilcFSMObject *SilcFSM; * * The actual FSM context and can be used as pre-allocated FSM context, * instead of SilcFSM context. This context is initialized with the - * silc_fsm_init function. It is uninitialized with silc_fsm_uninit. + * silc_fsm_init function. It need not be uninitialized. * ***/ typedef struct SilcFSMObject SilcFSMStruct; @@ -101,8 +101,7 @@ typedef struct SilcFSMObject *SilcFSMThread; * * FSM thread context and can be used as a pre-allocated FSM thread context, * instead of SilcFSMThread context. This context is initialized with the - * silc_fsm_thread_init function. It is uninitialized with the - * silc_fsm_uninit function. + * silc_fsm_thread_init function. It need not be uninitialized. * ***/ typedef struct SilcFSMObject SilcFSMThreadStruct; @@ -536,26 +535,6 @@ void silc_fsm_thread_init(SilcFSMThread thread, ***/ void silc_fsm_free(void *fsm); -/****f* silcutil/SilcFSMAPI/silc_fsm_uninit - * - * SYNOPSIS - * - * void silc_fsm_uninit(void *fsm); - * - * DESCRIPTION - * - * Uninitializes a pre-allocated SilcFSM or SilcFSMThread context. - * If you used the function silc_fsm_init or silc_fsm_thread_init, call - * this function to uninitialize it. This function is used with both - * SilcFSMStruct and SilcFSMThreadStruct contexts. - * - * NOTES - * - * When uninitializing FSM, it must not have any active threads. - * - ***/ -void silc_fsm_uninit(void *fsm); - /****f* silcutil/SilcFSMAPI/silc_fsm_start * * SYNOPSIS diff --git a/lib/silcutil/tests/test_silcfsm.c b/lib/silcutil/tests/test_silcfsm.c index c801a5e0..1a48aed1 100644 --- a/lib/silcutil/tests/test_silcfsm.c +++ b/lib/silcutil/tests/test_silcfsm.c @@ -258,9 +258,6 @@ SILC_FSM_STATE(test_st_eighth) } } - for (i = 0; i < NUM_THREADS; i++) - silc_fsm_uninit(&f->threads[i].thread); - SILC_LOG_DEBUG(("All %d threads terminated", NUM_THREADS)); /** Move to next thread */ @@ -320,9 +317,6 @@ SILC_FSM_STATE(test_st_tenth) f->threads2[i].finished = TRUE; } - for (i = 0; i < NUM_THREADS; i++) - silc_fsm_uninit(&f->threads2[i].thread); - SILC_LOG_DEBUG(("All %d real threads terminated", NUM_THREADS)); /** Finished successfully */