summaryrefslogtreecommitdiff
path: root/src/common/compress_zstd.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-04-25 10:46:23 -0400
committerNick Mathewson <nickm@torproject.org>2017-04-25 10:46:23 -0400
commit232c9e14a8319040c59fd9da1b5d242a57d10a04 (patch)
tree87557c905d81379c531416f59c8e4ad538cc7e77 /src/common/compress_zstd.c
parentec7c512d272d366e8e7de61aaf8108bca0adf957 (diff)
parent4266ec766af8e210ac52f597699b44818960ee39 (diff)
downloadtor-232c9e14a8319040c59fd9da1b5d242a57d10a04.tar.gz
tor-232c9e14a8319040c59fd9da1b5d242a57d10a04.zip
Merge branch 'atomic_counters'
Diffstat (limited to 'src/common/compress_zstd.c')
-rw-r--r--src/common/compress_zstd.c13
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);
+}