This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Hoernchen gerrit-no-reply at lists.osmocom.orgHoernchen has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/25414 ) Change subject: ratectr: make atomic ...................................................................... ratectr: make atomic This allows usage from different threads - (de)allocation is not threadsafe! Change-Id: I117f89add4798a250b5758543f1fb3e01d974205 --- M include/osmocom/core/rate_ctr.h M src/rate_ctr.c 2 files changed, 15 insertions(+), 9 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/14/25414/1 diff --git a/include/osmocom/core/rate_ctr.h b/include/osmocom/core/rate_ctr.h index d944cc0..ffaae91 100644 --- a/include/osmocom/core/rate_ctr.h +++ b/include/osmocom/core/rate_ctr.h @@ -5,7 +5,7 @@ * \file rate_ctr.h */ #include <stdint.h> - +#include <stdatomic.h> #include <osmocom/core/linuxlist.h> /*! Number of rate counter intervals */ @@ -21,14 +21,14 @@ /*! data we keep for each of the intervals */ struct rate_ctr_per_intv { - uint64_t last; /*!< counter value in last interval */ - uint64_t rate; /*!< counter rate */ + atomic_uint_fast64_t last; /*!< counter value in last interval */ + atomic_uint_fast64_t rate; /*!< counter rate */ }; /*! data we keep for each actual value */ struct rate_ctr { - uint64_t current; /*!< current value */ - uint64_t previous; /*!< previous value, used for delta */ + atomic_uint_fast64_t current; /*!< current value */ + atomic_uint_fast64_t previous; /*!< previous value, used for delta */ /*! per-interval data */ struct rate_ctr_per_intv intv[RATE_CTR_INTV_NUM]; }; diff --git a/src/rate_ctr.c b/src/rate_ctr.c index 4d99699..aa02005 100644 --- a/src/rate_ctr.c +++ b/src/rate_ctr.c @@ -68,7 +68,9 @@ #include <osmocom/core/rate_ctr.h> #include <osmocom/core/logging.h> -static LLIST_HEAD(rate_ctr_groups); +static __thread struct llist_head rate_ctr_groups; +static __thread struct osmo_timer_list rate_ctr_timer; +static __thread uint64_t timer_ticks; static void *tall_rate_ctr_ctx; @@ -314,9 +316,6 @@ ctr->intv[intv+1].rate += ctr->intv[intv].rate; } -static struct osmo_timer_list rate_ctr_timer; -static uint64_t timer_ticks; - /* The one-second interval has expired */ static void rate_ctr_group_intv(struct rate_ctr_group *grp) { @@ -354,6 +353,7 @@ * \returns 0 on success; negative on error */ int rate_ctr_init(void *tall_ctx) { + INIT_LLIST_HEAD(&rate_ctr_groups); tall_rate_ctr_ctx = tall_ctx; osmo_timer_setup(&rate_ctr_timer, rate_ctr_timer_cb, NULL); osmo_timer_schedule(&rate_ctr_timer, 1, 0); @@ -467,4 +467,10 @@ } } +/* ensure main thread always has pre-initialized osmo_fds */ +static __attribute__((constructor)) void on_dso_load_rate_ctr(void) +{ + INIT_LLIST_HEAD(&rate_ctr_groups); +} + /*! @} */ -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/25414 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I117f89add4798a250b5758543f1fb3e01d974205 Gerrit-Change-Number: 25414 Gerrit-PatchSet: 1 Gerrit-Owner: Hoernchen <ewild at sysmocom.de> Gerrit-MessageType: newchange -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210909/8c816b5d/attachment.htm>