Harald Welte | 216338c | 2017-10-15 19:46:19 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Daniel Willmann | 0a1259b | 2019-04-29 13:09:14 +0200 | [diff] [blame] | 3 | #include <osmocom/core/defs.h> |
| 4 | |
Harald Welte | 216338c | 2017-10-15 19:46:19 +0200 | [diff] [blame] | 5 | /*! \file counter.h |
| 6 | * Common routines regarding counter handling */ |
| 7 | |
Harald Welte | 17bbaa3 | 2017-10-15 20:02:07 +0200 | [diff] [blame] | 8 | /*! Structure representing a single counter */ |
Harald Welte | 216338c | 2017-10-15 19:46:19 +0200 | [diff] [blame] | 9 | struct osmo_counter { |
| 10 | struct llist_head list; /*!< internal list head */ |
| 11 | const char *name; /*!< human-readable name */ |
| 12 | const char *description; /*!< humn-readable description */ |
| 13 | unsigned long value; /*!< current value */ |
| 14 | unsigned long previous; /*!< previous value */ |
| 15 | }; |
| 16 | |
Harald Welte | 17bbaa3 | 2017-10-15 20:02:07 +0200 | [diff] [blame] | 17 | /*! Decrement given counter by one |
| 18 | * \param[in] ctr Counter that's to be decremented */ |
Daniel Willmann | 0a1259b | 2019-04-29 13:09:14 +0200 | [diff] [blame] | 19 | OSMO_DEPRECATED("Implement as osmo_stat_item instead") |
Harald Welte | 216338c | 2017-10-15 19:46:19 +0200 | [diff] [blame] | 20 | static inline void osmo_counter_dec(struct osmo_counter *ctr) |
| 21 | { |
| 22 | ctr->value--; |
| 23 | } |
| 24 | |
Harald Welte | 17bbaa3 | 2017-10-15 20:02:07 +0200 | [diff] [blame] | 25 | /*! Increment counter by one. |
| 26 | * \param[in] Counter that's to be incremented */ |
Daniel Willmann | 0a1259b | 2019-04-29 13:09:14 +0200 | [diff] [blame] | 27 | OSMO_DEPRECATED("Implement as osmo_stat_item instead") |
Harald Welte | 216338c | 2017-10-15 19:46:19 +0200 | [diff] [blame] | 28 | static inline void osmo_counter_inc(struct osmo_counter *ctr) |
| 29 | { |
| 30 | ctr->value++; |
| 31 | } |
| 32 | |
| 33 | /*! Get current value of counter */ |
Daniel Willmann | 0a1259b | 2019-04-29 13:09:14 +0200 | [diff] [blame] | 34 | OSMO_DEPRECATED("Implement as osmo_stat_item instead") |
Harald Welte | 216338c | 2017-10-15 19:46:19 +0200 | [diff] [blame] | 35 | static inline unsigned long osmo_counter_get(struct osmo_counter *ctr) |
| 36 | { |
| 37 | return ctr->value; |
| 38 | } |
| 39 | |
| 40 | /*! Reset current value of counter to 0 */ |
Daniel Willmann | 0a1259b | 2019-04-29 13:09:14 +0200 | [diff] [blame] | 41 | OSMO_DEPRECATED("Implement as osmo_stat_item instead") |
Harald Welte | 216338c | 2017-10-15 19:46:19 +0200 | [diff] [blame] | 42 | static inline void osmo_counter_reset(struct osmo_counter *ctr) |
| 43 | { |
| 44 | ctr->value = 0; |
| 45 | } |
| 46 | |
Daniel Willmann | 0a1259b | 2019-04-29 13:09:14 +0200 | [diff] [blame] | 47 | struct osmo_counter *osmo_counter_alloc(const char *name) |
| 48 | OSMO_DEPRECATED("Implement as osmo_stat_item instead"); |
Harald Welte | 216338c | 2017-10-15 19:46:19 +0200 | [diff] [blame] | 49 | |
Daniel Willmann | 0a1259b | 2019-04-29 13:09:14 +0200 | [diff] [blame] | 50 | void osmo_counter_free(struct osmo_counter *ctr) |
| 51 | OSMO_DEPRECATED("Implement as osmo_stat_item instead"); |
Harald Welte | 216338c | 2017-10-15 19:46:19 +0200 | [diff] [blame] | 52 | |
Harald Welte | 216338c | 2017-10-15 19:46:19 +0200 | [diff] [blame] | 53 | int osmo_counters_for_each(int (*handle_counter)(struct osmo_counter *, void *), void *data); |
| 54 | |
Alexander Couzens | 18ba26c | 2017-12-05 16:06:27 +0100 | [diff] [blame] | 55 | int osmo_counters_count(); |
| 56 | |
Harald Welte | 216338c | 2017-10-15 19:46:19 +0200 | [diff] [blame] | 57 | struct osmo_counter *osmo_counter_get_by_name(const char *name); |
| 58 | |
Harald Welte | 216338c | 2017-10-15 19:46:19 +0200 | [diff] [blame] | 59 | int osmo_counter_difference(struct osmo_counter *ctr); |