diff options
| author | Garrett D'Amore <garrett@damore.org> | 2019-12-29 14:39:27 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2019-12-29 15:21:42 -0800 |
| commit | b4d3ff2d460607ba8e1b351233cb6cbe9f031264 (patch) | |
| tree | 74a9aba0717f74404438bbca1bdc75a9e6105abf /src/core/stats.c | |
| parent | e457590015f8c3f4e840e4bed290f052c001e07c (diff) | |
| download | nng-b4d3ff2d460607ba8e1b351233cb6cbe9f031264.tar.gz nng-b4d3ff2d460607ba8e1b351233cb6cbe9f031264.tar.bz2 nng-b4d3ff2d460607ba8e1b351233cb6cbe9f031264.zip | |
fixes #1064 Potential deadlock in statistics code
fixes #1063 Include sanitizer runs in CI
fixes #1068 Wssfile test sometimes fails with wrong error code
While here, addressed a number of clang-tidy items, and some light
cleanup of code we were already in.
Diffstat (limited to 'src/core/stats.c')
| -rw-r--r-- | src/core/stats.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/core/stats.c b/src/core/stats.c index 247e7ab4..74b14f59 100644 --- a/src/core/stats.c +++ b/src/core/stats.c @@ -36,13 +36,9 @@ static nni_mtx * stats_held = NULL; #endif void -nni_stat_append(nni_stat_item *parent, nni_stat_item *child) +nni_stat_add(nni_stat_item *parent, nni_stat_item *child) { #ifdef NNG_ENABLE_STATS - if (parent == NULL) { - parent = &stats_root; - } - nni_mtx_lock(&stats_lock); // Make sure that the lists for both children and parents // are correctly initialized. if (parent->si_children.ll_head.ln_next == NULL) { @@ -53,15 +49,24 @@ nni_stat_append(nni_stat_item *parent, nni_stat_item *child) } nni_list_append(&parent->si_children, child); child->si_parent = parent; - nni_mtx_unlock(&stats_lock); #else NNI_ARG_UNUSED(parent); NNI_ARG_UNUSED(child); #endif } +// nni_stat_register registers a stat tree, acquiring the lock +// on the stats structures before doing so. +void +nni_stat_register(nni_stat_item *child) +{ + nni_mtx_lock(&stats_lock); + nni_stat_add(&stats_root, child); + nni_mtx_unlock(&stats_lock); +} + void -nni_stat_remove(nni_stat_item *child) +nni_stat_unregister(nni_stat_item *child) { #ifdef NNG_ENABLE_STATS nni_stat_item *parent; @@ -141,7 +146,6 @@ stat_atomic_update(nni_stat_item *stat, void *notused) void nni_stat_init_atomic(nni_stat_item *stat, const char *name, const char *desc) { - nni_stat_init(stat, name, desc); stat->si_number = 0; stat->si_private = NULL; |
