diff options
| author | Garrett D'Amore <garrett@damore.org> | 2019-05-19 14:33:36 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2019-05-19 14:33:36 -0700 |
| commit | 6fe3ff90cd86d539371403381f6c580fc097e689 (patch) | |
| tree | a214819298baf6d6e53d6abd7cff9a0271488d7f /src/core | |
| parent | c40cc5d16dbb22c46e47a1028265b8ee9fb5df27 (diff) | |
| download | nng-6fe3ff90cd86d539371403381f6c580fc097e689.tar.gz nng-6fe3ff90cd86d539371403381f6c580fc097e689.tar.bz2 nng-6fe3ff90cd86d539371403381f6c580fc097e689.zip | |
fix #946 Use after free in TLS
This also introduces a more efficient reference counting usage based
on atomics, rather than locks.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/platform.h | 6 | ||||
| -rw-r--r-- | src/core/stats.c | 4 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/core/platform.h b/src/core/platform.h index 1418ba4f..65d9af82 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -172,11 +172,13 @@ extern void nni_atomic_flag_reset(nni_atomic_flag *); typedef struct nni_atomic_u64 nni_atomic_u64; extern void nni_atomic_init64(nni_atomic_u64 *); -extern void nni_atomic_inc64(nni_atomic_u64 *, uint64_t); -extern void nni_atomic_dec64(nni_atomic_u64 *, uint64_t); +extern void nni_atomic_add64(nni_atomic_u64 *, uint64_t); +extern void nni_atomic_sub64(nni_atomic_u64 *, uint64_t); extern uint64_t nni_atomic_get64(nni_atomic_u64 *); extern void nni_atomic_set64(nni_atomic_u64 *, uint64_t); extern uint64_t nni_atomic_swap64(nni_atomic_u64 *, uint64_t); +extern uint64_t nni_atomic_dec64_nv(nni_atomic_u64 *); +extern void nni_atomic_inc64(nni_atomic_u64 *); // // Clock Support diff --git a/src/core/stats.c b/src/core/stats.c index f3f969c3..247e7ab4 100644 --- a/src/core/stats.c +++ b/src/core/stats.c @@ -152,13 +152,13 @@ nni_stat_init_atomic(nni_stat_item *stat, const char *name, const char *desc) void nni_stat_inc_atomic(nni_stat_item *stat, uint64_t inc) { - nni_atomic_inc64(&stat->si_atomic, inc); + nni_atomic_add64(&stat->si_atomic, inc); } void nni_stat_dec_atomic(nni_stat_item *stat, uint64_t inc) { - nni_atomic_dec64(&stat->si_atomic, inc); + nni_atomic_sub64(&stat->si_atomic, inc); } #endif |
