summaryrefslogtreecommitdiff
path: root/src/common/compress_lzma.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-04-25 10:29:07 -0400
committerNick Mathewson <nickm@torproject.org>2017-04-25 10:29:07 -0400
commit4266ec766af8e210ac52f597699b44818960ee39 (patch)
tree902ce2bd58a59f78b8317e2277ecddbf233cdae3 /src/common/compress_lzma.c
parent91dd4a00f7d4891e24187a849933547128aeeb9f (diff)
downloadtor-4266ec766af8e210ac52f597699b44818960ee39.tar.gz
tor-4266ec766af8e210ac52f597699b44818960ee39.zip
Use atomic counters for compressor allocation.
Diffstat (limited to 'src/common/compress_lzma.c')
-rw-r--r--src/common/compress_lzma.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/common/compress_lzma.c b/src/common/compress_lzma.c
index ae0327f581..b0ba4b6ba8 100644
--- a/src/common/compress_lzma.c
+++ b/src/common/compress_lzma.c
@@ -23,7 +23,7 @@
#endif
/** Total number of bytes allocated for LZMA state. */
-static size_t total_lzma_allocation = 0;
+static atomic_counter_t total_lzma_allocation;
#ifdef HAVE_LZMA
/** Given <b>level</b> return the memory level. */
@@ -465,6 +465,7 @@ tor_lzma_compress_new(int compress,
}
}
+ atomic_counter_add(&total_lzma_allocation, result->allocation);
return result;
err:
@@ -579,7 +580,7 @@ tor_lzma_compress_free(tor_lzma_compress_state_t *state)
if (state == NULL)
return;
- total_lzma_allocation -= state->allocation;
+ atomic_counter_sub(&total_lzma_allocation, state->allocation);
#ifdef HAVE_LZMA
lzma_end(&state->stream);
@@ -600,6 +601,12 @@ tor_lzma_compress_state_size(const tor_lzma_compress_state_t *state)
size_t
tor_lzma_get_total_allocation(void)
{
- return total_lzma_allocation;
+ return atomic_counter_get(&total_lzma_allocation);
}
+/** Initialize the lzma module */
+void
+tor_lzma_init(void)
+{
+ atomic_counter_init(&total_lzma_allocation);
+}