1 #ifndef JEMALLOC_INTERNAL_TICKER_INLINES_H
2 #define JEMALLOC_INTERNAL_TICKER_INLINES_H
3
4 #ifndef JEMALLOC_ENABLE_INLINE
5 void ticker_init(ticker_t *ticker, int32_t nticks);
6 void ticker_copy(ticker_t *ticker, const ticker_t *other);
7 int32_t ticker_read(const ticker_t *ticker);
8 bool ticker_ticks(ticker_t *ticker, int32_t nticks);
9 bool ticker_tick(ticker_t *ticker);
10 #endif
11
12 #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_TICKER_C_))
13 JEMALLOC_INLINE void
ticker_init(ticker_t * ticker,int32_t nticks)14 ticker_init(ticker_t *ticker, int32_t nticks)
15 {
16 ticker->tick = nticks;
17 ticker->nticks = nticks;
18 }
19
20 JEMALLOC_INLINE void
ticker_copy(ticker_t * ticker,const ticker_t * other)21 ticker_copy(ticker_t *ticker, const ticker_t *other)
22 {
23 *ticker = *other;
24 }
25
26 JEMALLOC_INLINE int32_t
ticker_read(const ticker_t * ticker)27 ticker_read(const ticker_t *ticker)
28 {
29 return (ticker->tick);
30 }
31
32 JEMALLOC_INLINE bool
ticker_ticks(ticker_t * ticker,int32_t nticks)33 ticker_ticks(ticker_t *ticker, int32_t nticks)
34 {
35 if (unlikely(ticker->tick < nticks)) {
36 ticker->tick = ticker->nticks;
37 return (true);
38 }
39 ticker->tick -= nticks;
40 return(false);
41 }
42
43 JEMALLOC_INLINE bool
ticker_tick(ticker_t * ticker)44 ticker_tick(ticker_t *ticker)
45 {
46 return (ticker_ticks(ticker, 1));
47 }
48 #endif
49
50 #endif /* JEMALLOC_INTERNAL_TICKER_INLINES_H */
51