diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-04-25 10:29:07 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-04-25 10:29:07 -0400 |
commit | 4266ec766af8e210ac52f597699b44818960ee39 (patch) | |
tree | 902ce2bd58a59f78b8317e2277ecddbf233cdae3 /src/common/compress_zstd.c | |
parent | 91dd4a00f7d4891e24187a849933547128aeeb9f (diff) | |
download | tor-4266ec766af8e210ac52f597699b44818960ee39.tar.gz tor-4266ec766af8e210ac52f597699b44818960ee39.zip |
Use atomic counters for compressor allocation.
Diffstat (limited to 'src/common/compress_zstd.c')
-rw-r--r-- | src/common/compress_zstd.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/common/compress_zstd.c b/src/common/compress_zstd.c index 664cce1700..8725c10538 100644 --- a/src/common/compress_zstd.c +++ b/src/common/compress_zstd.c @@ -24,7 +24,7 @@ #endif /** Total number of bytes allocated for Zstandard state. */ -static size_t total_zstd_allocation = 0; +static atomic_counter_t total_zstd_allocation; #ifdef HAVE_ZSTD /** Given <b>level</b> return the memory level. */ @@ -446,6 +446,7 @@ tor_zstd_compress_new(int compress, } } + atomic_counter_add(&total_zstd_allocation, result->allocation); return result; err: @@ -578,7 +579,7 @@ tor_zstd_compress_free(tor_zstd_compress_state_t *state) if (state == NULL) return; - total_zstd_allocation -= state->allocation; + atomic_counter_sub(&total_zstd_allocation, state->allocation); #ifdef HAVE_ZSTD if (state->compress) { @@ -604,6 +605,12 @@ tor_zstd_compress_state_size(const tor_zstd_compress_state_t *state) size_t tor_zstd_get_total_allocation(void) { - return total_zstd_allocation; + return atomic_counter_get(&total_zstd_allocation); } +/** Initialize the zstd module */ +void +tor_zstd_init(void) +{ + atomic_counter_init(&total_zstd_allocation); +} |