fsm->schedule = schedule;
fsm->thread = FALSE;
fsm->async_call = FALSE;
+ fsm->started = FALSE;
fsm->u.m.threads = 0;
fsm->u.m.lock = NULL;
thread->schedule = fsm->schedule;
thread->thread = TRUE;
thread->async_call = FALSE;
+ thread->started = FALSE;
thread->real_thread = real_thread;
thread->u.t.fsm = fsm;
void silc_fsm_free(void *fsm)
{
SilcFSM f = fsm;
- silc_schedule_task_add_timeout(f->schedule, silc_fsm_free_final, f, 0, 0);
+ if (!f->thread)
+ silc_schedule_task_add_timeout(f->schedule, silc_fsm_free_final, f, 0, 0);
+ else
+ silc_fsm_free_final(f->schedule, silc_schedule_get_context(f->schedule),
+ 0, 0, f);
}
/* Task to start real thread. We start threads through scheduler, not
f->finished = FALSE;
f->next_state = start_state;
f->synchronous = FALSE;
+ f->started = TRUE;
/* Start real thread through scheduler */
if (f->thread && f->real_thread) {
f->finished = FALSE;
f->next_state = start_state;
f->synchronous = TRUE;
+ f->started = TRUE;
/* Start real thread directly */
if (f->thread && f->real_thread) {
SILC_ASSERT(!f->finished);
f->finished = TRUE;
+ f->started = FALSE;
+
+ silc_schedule_task_del_by_all(f->schedule, 0, silc_fsm_run, f);
+ f->next_later = FALSE;
/* If we are thread and using real threads, the FSM thread will finish
after the real thread has finished, in the main thread. */
return (SilcFSM)thread->u.t.fsm;
}
+/* Returns TRUE if FSM is started and not yet finished */
+
+SilcBool silc_fsm_is_started(void *fsm)
+{
+ SilcFSM f = fsm;
+
+ if (f->started && !f->finished)
+ return TRUE;
+
+ return FALSE;
+}
+
/* Set context */
void silc_fsm_set_context(void *fsm, void *fsm_context)
***/
SilcFSM silc_fsm_get_machine(SilcFSMThread thread);
+/****f* silcutil/SilcFSMAPI/silc_fsm_is_started
+ *
+ * SYNOPSIS
+ *
+ * SilcBool silc_fsm_is_started(void *fsm);
+ *
+ * DESCRIPTION
+ *
+ * Returns TRUE if the machine or thread `fsm' has been started and has
+ * not been finished yet. This function is used with both SilcFSM and
+ * SilcFSMThread contexts.
+ *
+ ***/
+SilcBool silc_fsm_is_started(void *fsm);
/* FSM Semaphores */