From 7b74551b93421d30d5f0346042993ff763ddbe25 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 18 May 2019 21:03:55 +0200 Subject: fsm: Allow millisecond granularity in osmo_fsm built-in timer So far, the public API of osmo_fsm only allowed integral seconds as timeout. Let's change that to milli-seconds in order to cover more use cases. This introduces * osmo_fsm_inst_state_chg_ms() * osmo_fsm_inst_state_chg_keep_or_start_timer_ms() Which both work exactly like their previous counterparts without the _ms suffix - the only difference being that the timeout parameter is specified in milli-seconds, not in seconds. The value range for an unsigned long in milli-seconds even on a 32bit platform extends to about 48 days. This patch also removes the documentation notice about limiting the maximum value to 0x7fffffff due to time_t signed-ness. We don't use time_t but unsigned long. Change-Id: I35b330e460e80bb67376c77e997e464439ac5397 --- include/osmocom/core/fsm.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include/osmocom/core/fsm.h') diff --git a/include/osmocom/core/fsm.h b/include/osmocom/core/fsm.h index 41d01a58..1701c45e 100644 --- a/include/osmocom/core/fsm.h +++ b/include/osmocom/core/fsm.h @@ -243,6 +243,13 @@ int _osmo_fsm_inst_state_chg(struct osmo_fsm_inst *fi, uint32_t new_state, unsigned long timeout_secs, int T, const char *file, int line); +#define osmo_fsm_inst_state_chg_ms(fi, new_state, timeout_ms, T) \ + _osmo_fsm_inst_state_chg_ms(fi, new_state, timeout_ms, T, \ + __FILE__, __LINE__) +int _osmo_fsm_inst_state_chg_ms(struct osmo_fsm_inst *fi, uint32_t new_state, + unsigned long timeout_ms, int T, + const char *file, int line); + /*! perform a state change while keeping the current timer running. * * This is useful to keep a timeout across several states (without having to round the @@ -273,6 +280,14 @@ int _osmo_fsm_inst_state_chg_keep_or_start_timer(struct osmo_fsm_inst *fi, uint3 unsigned long timeout_secs, int T, const char *file, int line); +#define osmo_fsm_inst_state_chg_keep_or_start_timer_ms(fi, new_state, timeout_ms, T) \ + _osmo_fsm_inst_state_chg_keep_or_start_timer_ms(fi, new_state, timeout_ms, T, \ + __FILE__, __LINE__) +int _osmo_fsm_inst_state_chg_keep_or_start_timer_ms(struct osmo_fsm_inst *fi, uint32_t new_state, + unsigned long timeout_ms, int T, + const char *file, int line); + + /*! dispatch an event to an osmocom finite state machine instance * * This is a macro that calls _osmo_fsm_inst_dispatch() with the given -- cgit v1.2.3