[tor-commits] [tor/master] Add a helper function to decrement read and write at the same time

nickm at torproject.org nickm at torproject.org
Fri Apr 13 14:47:29 UTC 2018


commit 8a852397462e39cfbc21e3cea20ddd39be40598d
Author: Nick Mathewson <nickm at torproject.org>
Date:   Tue Apr 10 12:33:30 2018 -0400

    Add a helper function to decrement read and write at the same time
---
 src/common/token_bucket.c | 11 +++++++++++
 src/common/token_bucket.h |  3 +++
 2 files changed, 14 insertions(+)

diff --git a/src/common/token_bucket.c b/src/common/token_bucket.c
index f4d2cccff..abb050183 100644
--- a/src/common/token_bucket.c
+++ b/src/common/token_bucket.c
@@ -178,3 +178,14 @@ token_bucket_dec_write(token_bucket_t *bucket,
   return decrement_single_bucket(&bucket->write_bucket, n);
 }
 
+/**
+ * As token_bucket_dec_read and token_bucket_dec_write, in a single operation.
+ */
+void
+token_bucket_dec(token_bucket_t *bucket,
+                 ssize_t n_read, ssize_t n_written)
+{
+  token_bucket_dec_read(bucket, n_read);
+  token_bucket_dec_read(bucket, n_written);
+}
+
diff --git a/src/common/token_bucket.h b/src/common/token_bucket.h
index ef0735219..2d1ccd5cf 100644
--- a/src/common/token_bucket.h
+++ b/src/common/token_bucket.h
@@ -43,6 +43,9 @@ int token_bucket_dec_read(token_bucket_t *bucket,
 int token_bucket_dec_write(token_bucket_t *bucket,
                            ssize_t n);
 
+void token_bucket_dec(token_bucket_t *bucket,
+                      ssize_t n_read, ssize_t n_written);
+
 static inline size_t token_bucket_get_read(const token_bucket_t *bucket);
 static inline size_t
 token_bucket_get_read(const token_bucket_t *bucket)





More information about the tor-commits mailing list