From 0ec656eb7117127602f295510de694083353f23e Mon Sep 17 00:00:00 2001 From: Dave Watson Date: Tue, 16 Oct 2018 10:23:08 -0700 Subject: [PATCH] ticker: add ticker_trytick For the fastpath, we want to tick, but undo the tick and jump to the slowpath if ticker would fire. --- include/jemalloc/internal/ticker.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/jemalloc/internal/ticker.h b/include/jemalloc/internal/ticker.h index 4b360470..52d0db4c 100644 --- a/include/jemalloc/internal/ticker.h +++ b/include/jemalloc/internal/ticker.h @@ -75,4 +75,17 @@ ticker_tick(ticker_t *ticker) { return ticker_ticks(ticker, 1); } +/* + * Try to tick. If ticker would fire, return true, but rely on + * slowpath to reset ticker. + */ +static inline bool +ticker_trytick(ticker_t *ticker) { + --ticker->tick; + if (unlikely(ticker->tick < 0)) { + return true; + } + return false; +} + #endif /* JEMALLOC_INTERNAL_TICKER_H */