Skip to content

Commit

Permalink
fsm: Add general fsm cancel timer function
Browse files Browse the repository at this point in the history
  • Loading branch information
wipawel committed Jan 30, 2015
1 parent f34ae54 commit a7ea8b7
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/fsm.c
Expand Up @@ -429,14 +429,16 @@ __ni_ifworker_timeout(void *user_data, const ni_timer_t *timer)
ni_ifworker_timeout_count++;
}

static void
ni_ifworker_cancel_timeout(ni_ifworker_t *w)
static ni_bool_t
__ni_fsm_cancel_timeout(const ni_timer_t **timer)
{
if (w->fsm.timer) {
ni_timer_cancel(w->fsm.timer);
w->fsm.timer = NULL;
ni_debug_application("%s: cancel timeout", w->name);
if (timer && *timer) {
ni_timer_cancel(*timer);
*timer = NULL;
return TRUE;
}

return FALSE;
}

static inline void
Expand All @@ -446,6 +448,13 @@ __ni_fsm_set_timeout(const ni_timer_t **timer, unsigned long timeout_ms, void (*
*timer = ni_timer_register(timeout_ms, handler, data);
}

static inline void
ni_ifworker_cancel_timeout(ni_ifworker_t *w)
{
if (__ni_fsm_cancel_timeout(&w->fsm.timer))
ni_debug_application("%s: cancel worker's timeout", w->name);
}

static inline void
ni_ifworker_set_timeout(ni_ifworker_t *w, unsigned long timeout_ms)
{
Expand All @@ -456,8 +465,7 @@ ni_ifworker_set_timeout(ni_ifworker_t *w, unsigned long timeout_ms)
static inline void
ni_ifworker_set_secondary_timeout(ni_ifworker_t *w, unsigned long timeout_ms, void (*handler)(void *, const ni_timer_t *))
{
if (w->fsm.secondary_timer)
ni_timer_cancel(w->fsm.secondary_timer);
__ni_fsm_cancel_timeout(&w->fsm.secondary_timer);
__ni_fsm_set_timeout(&w->fsm.secondary_timer, timeout_ms, handler, w);
}

Expand Down

0 comments on commit a7ea8b7

Please sign in to comment.