mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-24 22:58:50 +01:00
Add functions to enable/disable periodic_event_t objects.
This commit is contained in:
parent
fa7847e450
commit
80f582ae18
2 changed files with 32 additions and 1 deletions
|
@ -253,10 +253,39 @@ periodic_timer_new(struct event_base *base,
|
||||||
}
|
}
|
||||||
timer->cb = cb;
|
timer->cb = cb;
|
||||||
timer->data = data;
|
timer->data = data;
|
||||||
event_add(timer->ev, (struct timeval *)tv); /*drop const for old libevent*/
|
periodic_timer_launch(timer, tv);
|
||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launch the timer <b>timer</b> to run at <b>tv</b> from now, and every
|
||||||
|
* <b>tv</b> thereafter.
|
||||||
|
*
|
||||||
|
* If the timer is already enabled, this function does nothing.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
periodic_timer_launch(periodic_timer_t *timer, const struct timeval *tv)
|
||||||
|
{
|
||||||
|
tor_assert(timer);
|
||||||
|
if (event_pending(timer->ev, EV_TIMEOUT, NULL))
|
||||||
|
return;
|
||||||
|
event_add(timer->ev, (struct timeval *)tv); /*drop const for old libevent*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable the provided <b>timer</b>, but do not free it.
|
||||||
|
*
|
||||||
|
* You can reenable the same timer later with periodic_timer_launch.
|
||||||
|
*
|
||||||
|
* If the timer is already disabled, this function does nothing.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
periodic_timer_disable(periodic_timer_t *timer)
|
||||||
|
{
|
||||||
|
tor_assert(timer);
|
||||||
|
event_del(timer->ev);
|
||||||
|
}
|
||||||
|
|
||||||
/** Stop and free a periodic timer */
|
/** Stop and free a periodic timer */
|
||||||
void
|
void
|
||||||
periodic_timer_free_(periodic_timer_t *timer)
|
periodic_timer_free_(periodic_timer_t *timer)
|
||||||
|
|
|
@ -31,6 +31,8 @@ periodic_timer_t *periodic_timer_new(struct event_base *base,
|
||||||
void (*cb)(periodic_timer_t *timer, void *data),
|
void (*cb)(periodic_timer_t *timer, void *data),
|
||||||
void *data);
|
void *data);
|
||||||
void periodic_timer_free_(periodic_timer_t *);
|
void periodic_timer_free_(periodic_timer_t *);
|
||||||
|
void periodic_timer_launch(periodic_timer_t *, const struct timeval *tv);
|
||||||
|
void periodic_timer_disable(periodic_timer_t *);
|
||||||
#define periodic_timer_free(t) \
|
#define periodic_timer_free(t) \
|
||||||
FREE_AND_NULL(periodic_timer_t, periodic_timer_free_, (t))
|
FREE_AND_NULL(periodic_timer_t, periodic_timer_free_, (t))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue