1 /* utility routines for keeping some statistics */
3 /* (C) 2009 by Harald Welte <laforge@gnumonks.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <osmocom/core/linuxlist.h>
26 #include <osmocom/core/talloc.h>
27 #include <osmocom/core/statistics.h>
29 static LLIST_HEAD(counters);
33 struct osmo_counter *osmo_counter_alloc(const char *name)
35 struct osmo_counter *ctr = talloc_zero(tall_ctr_ctx, struct osmo_counter);
41 llist_add_tail(&ctr->list, &counters);
46 void osmo_counter_free(struct osmo_counter *ctr)
48 llist_del(&ctr->list);
52 int osmo_counters_for_each(int (*handle_counter)(struct osmo_counter *, void *),
55 struct osmo_counter *ctr;
58 llist_for_each_entry(ctr, &counters, list) {
59 rc = handle_counter(ctr, data);
67 struct osmo_counter *osmo_counter_get_by_name(const char *name)
69 struct osmo_counter *ctr;
71 llist_for_each_entry(ctr, &counters, list) {
72 if (!strcmp(ctr->name, name))