From 69249b82d8cf66a472ab26d7af8a05e6b83354b9 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Mon, 11 Sep 2006 15:04:50 +0000 Subject: [PATCH] Added SILC_FSM_YIELD. --- lib/silcutil/silcfsm.c | 5 +++++ lib/silcutil/silcfsm.h | 18 +++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/silcutil/silcfsm.c b/lib/silcutil/silcfsm.c index 863516da..7a0bf4ac 100644 --- a/lib/silcutil/silcfsm.c +++ b/lib/silcutil/silcfsm.c @@ -343,6 +343,11 @@ SILC_TASK_CALLBACK(silc_fsm_run) while (status == SILC_FSM_CONTINUE); switch (status) { + case SILC_FSM_YIELD: + /* Continue through scheduler */ + silc_fsm_continue(fsm); + break; + case SILC_FSM_WAIT: /* The machine is in hold */ SILC_LOG_DEBUG(("State wait %p", fsm)); diff --git a/lib/silcutil/silcfsm.h b/lib/silcutil/silcfsm.h index d1e253ec..0eb707c8 100644 --- a/lib/silcutil/silcfsm.h +++ b/lib/silcutil/silcfsm.h @@ -29,8 +29,8 @@ * threads. * * The FSM provides semaphores because of their versatility. The FSM - * semaphores can be used as a conditional variables and signallers, and - * also as a mutual exclusion locks to protect critical sections. The FSM + * semaphores can be used as mutual exclusion locks to protect critical + * sections, and as conditional variables and signallers. The FSM * semaphores can safely be used to synchronize also FSM threads that are * executed in real system threads. This makes SILC FSM very effective * tool to implement complex machines whether they are executed in single @@ -114,12 +114,14 @@ typedef struct SilcFSMObject SilcFSMThreadStruct; * * DESCRIPTION * - * Status values that the FSM state functions return. + * Status values that the FSM state functions return. They dicatate + * how the machine will behave after returning from the state function. * * SOURCE */ typedef enum { - SILC_FSM_CONTINUE, /* Continue immediately to next state. */ + SILC_FSM_CONTINUE, /* Continue immediately to next state */ + SILC_FSM_YIELD, /* Continue to next state through scheduler */ SILC_FSM_WAIT, /* Wait for some async call or timeout */ SILC_FSM_FINISH, /* Finish state machine and call destructor through scheduler */ @@ -588,9 +590,11 @@ void silc_fsm_start_sync(void *fsm, SilcFSMStateCallback start_state); * * Set the next state to be executed. If the state function that * call this function returns SILC_FSM_CONTINUE, the `next_state' - * will be executed immediately. This function must always be used - * to set the next state in the machine or thread. This function is - * used with both SilcFSM and SilcFSMThread contexts. + * will be executed immediately. If it returns SILC_FSM_YIELD it + * yields the thread and the `next_state' will be run after other + * threads have run first. This function must always be used to set + * the next state in the machine or thread. This function is used + * with both SilcFSM and SilcFSMThread contexts. * * EXAMPLE * -- 2.24.0