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_zlib.c | |
parent | 91dd4a00f7d4891e24187a849933547128aeeb9f (diff) | |
download | tor-4266ec766af8e210ac52f597699b44818960ee39.tar.gz tor-4266ec766af8e210ac52f597699b44818960ee39.zip |
Use atomic counters for compressor allocation.
Diffstat (limited to 'src/common/compress_zlib.c')
-rw-r--r-- | src/common/compress_zlib.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/common/compress_zlib.c b/src/common/compress_zlib.c index faa179f7c1..5425f205a0 100644 --- a/src/common/compress_zlib.c +++ b/src/common/compress_zlib.c @@ -48,7 +48,7 @@ static size_t tor_zlib_state_size_precalc(int inflate, int windowbits, int memlevel); /** Total number of bytes allocated for zlib state */ -static size_t total_zlib_allocation = 0; +static atomic_counter_t total_zlib_allocation; /** Given <b>level</b> return the memory level. */ static int @@ -437,7 +437,7 @@ tor_zlib_compress_new(int compress_, } out->allocation = tor_zlib_state_size_precalc(!compress_, bits, memlevel); - total_zlib_allocation += out->allocation; + atomic_counter_add(&total_zlib_allocation, out->allocation); return out; @@ -519,7 +519,7 @@ tor_zlib_compress_free(tor_zlib_compress_state_t *state) if (state == NULL) return; - total_zlib_allocation -= state->allocation; + atomic_counter_sub(&total_zlib_allocation, state->allocation); if (state->compress) deflateEnd(&state->stream); @@ -541,6 +541,12 @@ tor_zlib_compress_state_size(const tor_zlib_compress_state_t *state) size_t tor_zlib_get_total_allocation(void) { - return total_zlib_allocation; + return atomic_counter_get(&total_zlib_allocation); } +/** Set up global state for the zlib module */ +void +tor_zlib_init(void) +{ + atomic_counter_init(&total_zlib_allocation); +} |