1296221Sjasone/******************************************************************************/
2296221Sjasone#ifdef JEMALLOC_H_TYPES
3296221Sjasone
4296221Sjasonetypedef struct ticker_s ticker_t;
5296221Sjasone
6296221Sjasone#endif /* JEMALLOC_H_TYPES */
7296221Sjasone/******************************************************************************/
8296221Sjasone#ifdef JEMALLOC_H_STRUCTS
9296221Sjasone
10296221Sjasonestruct ticker_s {
11296221Sjasone	int32_t	tick;
12296221Sjasone	int32_t	nticks;
13296221Sjasone};
14296221Sjasone
15296221Sjasone#endif /* JEMALLOC_H_STRUCTS */
16296221Sjasone/******************************************************************************/
17296221Sjasone#ifdef JEMALLOC_H_EXTERNS
18296221Sjasone
19296221Sjasone#endif /* JEMALLOC_H_EXTERNS */
20296221Sjasone/******************************************************************************/
21296221Sjasone#ifdef JEMALLOC_H_INLINES
22296221Sjasone
23296221Sjasone#ifndef JEMALLOC_ENABLE_INLINE
24296221Sjasonevoid	ticker_init(ticker_t *ticker, int32_t nticks);
25296221Sjasonevoid	ticker_copy(ticker_t *ticker, const ticker_t *other);
26296221Sjasoneint32_t	ticker_read(const ticker_t *ticker);
27296221Sjasonebool	ticker_ticks(ticker_t *ticker, int32_t nticks);
28296221Sjasonebool	ticker_tick(ticker_t *ticker);
29296221Sjasone#endif
30296221Sjasone
31296221Sjasone#if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_TICKER_C_))
32296221SjasoneJEMALLOC_INLINE void
33296221Sjasoneticker_init(ticker_t *ticker, int32_t nticks)
34296221Sjasone{
35296221Sjasone
36296221Sjasone	ticker->tick = nticks;
37296221Sjasone	ticker->nticks = nticks;
38296221Sjasone}
39296221Sjasone
40296221SjasoneJEMALLOC_INLINE void
41296221Sjasoneticker_copy(ticker_t *ticker, const ticker_t *other)
42296221Sjasone{
43296221Sjasone
44296221Sjasone	*ticker = *other;
45296221Sjasone}
46296221Sjasone
47296221SjasoneJEMALLOC_INLINE int32_t
48296221Sjasoneticker_read(const ticker_t *ticker)
49296221Sjasone{
50296221Sjasone
51296221Sjasone	return (ticker->tick);
52296221Sjasone}
53296221Sjasone
54296221SjasoneJEMALLOC_INLINE bool
55296221Sjasoneticker_ticks(ticker_t *ticker, int32_t nticks)
56296221Sjasone{
57296221Sjasone
58296221Sjasone	if (unlikely(ticker->tick < nticks)) {
59296221Sjasone		ticker->tick = ticker->nticks;
60296221Sjasone		return (true);
61296221Sjasone	}
62296221Sjasone	ticker->tick -= nticks;
63296221Sjasone	return(false);
64296221Sjasone}
65296221Sjasone
66296221SjasoneJEMALLOC_INLINE bool
67296221Sjasoneticker_tick(ticker_t *ticker)
68296221Sjasone{
69296221Sjasone
70296221Sjasone	return (ticker_ticks(ticker, 1));
71296221Sjasone}
72296221Sjasone#endif
73296221Sjasone
74296221Sjasone#endif /* JEMALLOC_H_INLINES */
75296221Sjasone/******************************************************************************/
76