libosmocore  0.12.1
Osmocom core library
counter.h
Go to the documentation of this file.
1 #pragma once
2 
7 struct osmo_counter {
8  struct llist_head list;
9  const char *name;
10  const char *description;
11  unsigned long value;
12  unsigned long previous;
13 };
14 
17 static inline void osmo_counter_dec(struct osmo_counter *ctr)
18 {
19  ctr->value--;
20 }
21 
24 static inline void osmo_counter_inc(struct osmo_counter *ctr)
25 {
26  ctr->value++;
27 }
28 
30 static inline unsigned long osmo_counter_get(struct osmo_counter *ctr)
31 {
32  return ctr->value;
33 }
34 
36 static inline void osmo_counter_reset(struct osmo_counter *ctr)
37 {
38  ctr->value = 0;
39 }
40 
41 struct osmo_counter *osmo_counter_alloc(const char *name);
42 
43 void osmo_counter_free(struct osmo_counter *ctr);
44 
45 int osmo_counters_for_each(int (*handle_counter)(struct osmo_counter *, void *), void *data);
46 
48 
49 struct osmo_counter *osmo_counter_get_by_name(const char *name);
50 
51 int osmo_counter_difference(struct osmo_counter *ctr);
int osmo_counter_difference(struct osmo_counter *ctr)
Compute difference between current and previous counter value.
Definition: counter.c:106
static void osmo_counter_inc(struct osmo_counter *ctr)
Increment counter by one.
Definition: counter.h:24
int osmo_counters_count()
Counts the registered counter.
Definition: counter.c:82
const char * name
human-readable name
Definition: counter.h:9
static unsigned long osmo_counter_get(struct osmo_counter *ctr)
Get current value of counter.
Definition: counter.h:30
const char * description
humn-readable description
Definition: counter.h:10
(double) linked list header structure
Definition: linuxlist.h:46
static int handle_counter(struct osmo_counter *counter, void *sctx_)
Definition: stats.c:672
int osmo_counters_for_each(int(*handle_counter)(struct osmo_counter *, void *), void *data)
Iterate over all counters; call handle_cunter call-back for each.
Definition: counter.c:65
static void osmo_counter_reset(struct osmo_counter *ctr)
Reset current value of counter to 0.
Definition: counter.h:36
unsigned long previous
previous value
Definition: counter.h:12
Structure representing a single counter.
Definition: counter.h:7
struct llist_head list
internal list head
Definition: counter.h:8
unsigned long value
current value
Definition: counter.h:11
struct osmo_counter * osmo_counter_get_by_name(const char *name)
Find a counter by its name.
Definition: counter.c:90
static void osmo_counter_dec(struct osmo_counter *ctr)
Decrement given counter by one.
Definition: counter.h:17
void osmo_counter_free(struct osmo_counter *ctr)
Release/Destroy a given counter.
Definition: counter.c:55
struct osmo_counter * osmo_counter_alloc(const char *name)
Allocate a new counter with given name.
Definition: counter.c:40