[Tarantool-patches] [PATCH 2/8] fakesys: introduce fakeev_timer_remaining()
Serge Petrenko
sergepetrenko at tarantool.org
Tue Dec 15 12:43:18 MSK 2020
13.12.2020 20:15, Vladislav Shpilevoy пишет:
> ev_timer_remaining() in libev returns number of seconds until the
> timer will expire. It is used in raft code.
>
> Raft is going to be tested using fakesys, and it means it needs
> fakeev analogue of ev_timer_remaining().
>
> Part of #5303
Thanks for the patch!
LGTM.
> ---
> src/lib/fakesys/fakeev.c | 10 ++++++++++
> src/lib/fakesys/fakeev.h | 4 ++++
> 2 files changed, 14 insertions(+)
>
> diff --git a/src/lib/fakesys/fakeev.c b/src/lib/fakesys/fakeev.c
> index 8273c7ca8..715bf7b75 100644
> --- a/src/lib/fakesys/fakeev.c
> +++ b/src/lib/fakesys/fakeev.c
> @@ -282,6 +282,16 @@ fakeev_timer_start(struct ev_loop *loop, struct ev_timer *base)
> fakeev_timer_event_new((struct ev_watcher *)base, base->at);
> }
>
> +double
> +fakeev_timer_remaining(struct ev_loop *loop, struct ev_timer *base)
> +{
> + (void)loop;
> + struct fakeev_event *e = fakeev_event_by_ev((struct ev_watcher *)base);
> + if (e == NULL)
> + return base->at;
> + return e->deadline - fakeev_time();
> +}
> +
> void
> fakeev_timer_again(struct ev_loop *loop, struct ev_timer *base)
> {
> diff --git a/src/lib/fakesys/fakeev.h b/src/lib/fakesys/fakeev.h
> index 89954b2e1..6d1c4dcd1 100644
> --- a/src/lib/fakesys/fakeev.h
> +++ b/src/lib/fakesys/fakeev.h
> @@ -99,6 +99,10 @@ fakeev_loop(void);
> void
> fakeev_timer_start(struct ev_loop *loop, struct ev_timer *base);
>
> +/** Emulator of raft_ev_timer_remaining(). */
> +double
> +fakeev_timer_remaining(struct ev_loop *loop, struct ev_timer *base);
> +
> /** Emulator of ev_timer_again(). */
> void
> fakeev_timer_again(struct ev_loop *loop, struct ev_timer *base);
--
Serge Petrenko
More information about the Tarantool-patches
mailing list