From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 2733745C306 for ; Sun, 13 Dec 2020 20:15:35 +0300 (MSK) From: Vladislav Shpilevoy Date: Sun, 13 Dec 2020 18:15:24 +0100 Message-Id: <8b3f7ff8778f2270ce5598984b7df3750cdda4a6.1607879643.git.v.shpilevoy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 2/8] fakesys: introduce fakeev_timer_remaining() List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, sergepetrenko@tarantool.org 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 --- 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); -- 2.24.3 (Apple Git-128)