diff options
author | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2024-04-04 05:44:01 +0200 |
---|---|---|
committer | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2024-06-05 04:23:37 +0200 |
commit | 10cdcb0f177d894b4362064bfcd0b7b607ccf3e4 (patch) | |
tree | aebaa5a74a8628f91ba877352832e66d012720c8 /include/osmocom | |
parent | 4f0dbac51c994e56a53530c676f26aa64fde7b6d (diff) |
add osmo_stats_report_lock api
Allow multi-threaded access to reported stats:
- enable use of a stats mutex with osmo_stats_report_use_lock(true).
- lock/unlock externally with osmo_stats_report_lock(true/false).
Rationale:
A mutex lock around stats reporting is a very basic and very powerful
tool. It allows a multi-threaded application to decide which stats
updates will always be in sync.
For example, what if the main thread reports rate counters at exactly
the time a second thread updates rate counter values?
- is writing to stats atomic on a data type level?
- do applications need stats to be "atomic" as a whole?
We probably have (or can make) int64_t atomic, so that individual
counters will always be reported correctly.
But often, separate stats correspond to each other, which should not be
reported out of sync with each other. The simplest way to manage stats
sync in all cases is a mutex around the stats reporting.
But such a mutex isn't needed in most programs, with stats happening in
a single thread only. To completely avoid any overhead the mutex may
bring, make using a mutex optional with a global flag.
Related: SYS#6773
Related: osmo-hnbgw I9dc54e6bc94c553f45adfa71ae8ad70be4afbc8f
Change-Id: Ib335bea7d2a440ca284e6c439066f96456bf2c2d
Diffstat (limited to 'include/osmocom')
-rw-r--r-- | include/osmocom/core/stats.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/include/osmocom/core/stats.h b/include/osmocom/core/stats.h index a034a616..13aa979f 100644 --- a/include/osmocom/core/stats.h +++ b/include/osmocom/core/stats.h @@ -109,6 +109,9 @@ extern struct osmo_stats_config *osmo_stats_config; void osmo_stats_init(void *ctx); int osmo_stats_report(void); +void osmo_stats_report_use_lock(bool enable); +void osmo_stats_report_lock(void); +void osmo_stats_report_unlock(void); int osmo_stats_set_interval(int interval); |