This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Harald Welte gerrit-no-reply at lists.osmocom.orgReview at https://gerrit.osmocom.org/419 fsm: Introduce default time-out handling If a FSM doesn't specify any timer_cb, simply terminate the FSM by default on time-out. This is a reasonable default for most cases, and avoids copy+pasting a one-line timer_cb function in every FSM. Also, even if there is a timer_cb, let it have a return value to decide if the core should terminate after return from timer_cb or not. Change-Id: I0461a9593bfb729c82b7d1d1cf9f30b1079d0212 --- M include/osmocom/core/fsm.h M src/fsm.c 2 files changed, 16 insertions(+), 9 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/19/419/1 diff --git a/include/osmocom/core/fsm.h b/include/osmocom/core/fsm.h index 401ee04..ce0db15 100644 --- a/include/osmocom/core/fsm.h +++ b/include/osmocom/core/fsm.h @@ -26,6 +26,8 @@ OSMO_FSM_TERM_REGULAR, /*! \brief erroneous termination of process */ OSMO_FSM_TERM_ERROR, + /*! \brief termination due to time-out */ + OSMO_FSM_TERM_TIMEOUT, }; /*! \brief description of a rule in the FSM */ @@ -63,7 +65,7 @@ /*! \breif clean-up function, called during termination */ void (*cleanup)(struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause cause); /*! \brief timer call-back for states with time-out */ - void (*timer_cb)(struct osmo_fsm_inst *fi); + int (*timer_cb)(struct osmo_fsm_inst *fi); /*! \brief logging sub-system for this FSM */ int log_subsys; /*! \brief human-readable names of events */ diff --git a/src/fsm.c b/src/fsm.c index ede769d..8fedae2 100644 --- a/src/fsm.c +++ b/src/fsm.c @@ -136,10 +136,20 @@ { struct osmo_fsm_inst *fi = data; struct osmo_fsm *fsm = fi->fsm; + uint32_t T = fi->T; LOGPFSM(fi, "Timeout of T%u\n", fi->T); - fsm->timer_cb(fi); + if (fsm->timer_cb) { + int rc = fsm->timer_cb(fi); + if (rc != 1) + return; + LOGPFSM(fi, "timer_cb requested termination\n"); + } else + LOGPFSM(fi, "No timer_cb, automatic termination\n"); + + /* if timer_cb returns 1 or there is no timer_cb */ + osmo_fsm_inst_term(fi, OSMO_FSM_TERM_TIMEOUT, &T); } /*! \brief allocate a new instance of a specified FSM @@ -317,13 +327,8 @@ st->onenter(fi, old_state); if (timeout_secs) { - if (!fsm->timer_cb) - LOGP(fsm->log_subsys, LOGL_ERROR, "cannot start " - "timer for FSM without timer call-back\n"); - else { - fi->T = T; - osmo_timer_schedule(&fi->timer, timeout_secs, 0); - } + fi->T = T; + osmo_timer_schedule(&fi->timer, timeout_secs, 0); } return 0; -- To view, visit https://gerrit.osmocom.org/419 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0461a9593bfb729c82b7d1d1cf9f30b1079d0212 Gerrit-PatchSet: 1 Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Owner: Harald Welte <laforge at gnumonks.org>