Author: Pekka Riikonen <priikone@silcnet.org>
- 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
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);
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. */
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);
Author: Pekka Riikonen <priikone@silcnet.org>
- 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
*
* 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;
*
* 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;
***/
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
}
}
- 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 */
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 */