summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-04-13 10:51:59 -0400
committerNick Mathewson <nickm@torproject.org>2018-04-13 10:54:26 -0400
commit03b96882deb60cd21c3c77746f4f9cd4aac0a724 (patch)
treedc9f65dc453aa4d0eb468e74880fded889f4bd8e /src/common
parentb152d62cee7480ee7b9b68dd9b619db65b6cd112 (diff)
downloadtor-03b96882deb60cd21c3c77746f4f9cd4aac0a724.tar.gz
tor-03b96882deb60cd21c3c77746f4f9cd4aac0a724.zip
Rename token_bucket_t to token_bucket_rw_t.
This is a simple search-and-replace to rename the token bucket type to indicate that it contains both a read and a write bucket, bundled with their configuration. It's preliminary to refactoring the bucket type.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/token_bucket.c33
-rw-r--r--src/common/token_bucket.h33
2 files changed, 34 insertions, 32 deletions
diff --git a/src/common/token_bucket.c b/src/common/token_bucket.c
index 6af2982147..3191568ac3 100644
--- a/src/common/token_bucket.c
+++ b/src/common/token_bucket.c
@@ -41,14 +41,14 @@ rate_per_sec_to_rate_per_step(uint32_t rate)
* starts out full.
*/
void
-token_bucket_init(token_bucket_t *bucket,
+token_bucket_rw_init(token_bucket_rw_t *bucket,
uint32_t rate,
uint32_t burst,
uint32_t now_ts)
{
- memset(bucket, 0, sizeof(token_bucket_t));
- token_bucket_adjust(bucket, rate, burst);
- token_bucket_reset(bucket, now_ts);
+ memset(bucket, 0, sizeof(token_bucket_rw_t));
+ token_bucket_rw_adjust(bucket, rate, burst);
+ token_bucket_rw_reset(bucket, now_ts);
}
/**
@@ -56,14 +56,14 @@ token_bucket_init(token_bucket_t *bucket,
* for the token bucket in *<b>bucket</b>.
*/
void
-token_bucket_adjust(token_bucket_t *bucket,
+token_bucket_rw_adjust(token_bucket_rw_t *bucket,
uint32_t rate,
uint32_t burst)
{
tor_assert_nonfatal(rate > 0);
tor_assert_nonfatal(burst > 0);
- if (burst > TOKEN_BUCKET_MAX_BURST)
- burst = TOKEN_BUCKET_MAX_BURST;
+ if (burst > TOKEN_BUCKET_RW_MAX_BURST)
+ burst = TOKEN_BUCKET_RW_MAX_BURST;
bucket->rate = rate_per_sec_to_rate_per_step(rate);
bucket->burst = burst;
@@ -75,7 +75,7 @@ token_bucket_adjust(token_bucket_t *bucket,
* Reset <b>bucket</b> to be full, as of timestamp <b>now_ts</b>.
*/
void
-token_bucket_reset(token_bucket_t *bucket,
+token_bucket_rw_reset(token_bucket_rw_t *bucket,
uint32_t now_ts)
{
bucket->read_bucket = bucket->burst;
@@ -83,7 +83,7 @@ token_bucket_reset(token_bucket_t *bucket,
bucket->last_refilled_at_ts = now_ts;
}
-/* Helper: see token_bucket_refill */
+/* Helper: see token_bucket_rw_refill */
static int
refill_single_bucket(int32_t *bucketptr,
const uint32_t rate,
@@ -116,7 +116,7 @@ refill_single_bucket(int32_t *bucketptr,
* nonempty, and TB_WRITE iff the write bucket was empty and became nonempty.
*/
int
-token_bucket_refill(token_bucket_t *bucket,
+token_bucket_rw_refill(token_bucket_rw_t *bucket,
uint32_t now_ts)
{
const uint32_t elapsed_ticks = (now_ts - bucket->last_refilled_at_ts);
@@ -167,7 +167,7 @@ decrement_single_bucket(int32_t *bucketptr,
* otherwise.
*/
int
-token_bucket_dec_read(token_bucket_t *bucket,
+token_bucket_rw_dec_read(token_bucket_rw_t *bucket,
ssize_t n)
{
return decrement_single_bucket(&bucket->read_bucket, n);
@@ -180,20 +180,21 @@ token_bucket_dec_read(token_bucket_t *bucket,
* otherwise.
*/
int
-token_bucket_dec_write(token_bucket_t *bucket,
+token_bucket_rw_dec_write(token_bucket_rw_t *bucket,
ssize_t n)
{
return decrement_single_bucket(&bucket->write_bucket, n);
}
/**
- * As token_bucket_dec_read and token_bucket_dec_write, in a single operation.
+ * As token_bucket_rw_dec_read and token_bucket_rw_dec_write, in a single
+ * operation.
*/
void
-token_bucket_dec(token_bucket_t *bucket,
+token_bucket_rw_dec(token_bucket_rw_t *bucket,
ssize_t n_read, ssize_t n_written)
{
- token_bucket_dec_read(bucket, n_read);
- token_bucket_dec_read(bucket, n_written);
+ token_bucket_rw_dec_read(bucket, n_read);
+ token_bucket_rw_dec_read(bucket, n_written);
}
diff --git a/src/common/token_bucket.h b/src/common/token_bucket.h
index 2d1ccd5cf3..f9d04f79a5 100644
--- a/src/common/token_bucket.h
+++ b/src/common/token_bucket.h
@@ -2,8 +2,8 @@
/* See LICENSE for licensing information */
/**
- * \file token_bucket.h
- * \brief Headers for token_bucket.c
+ * \file token_bucket_rw.h
+ * \brief Headers for token_bucket_rw.c
**/
#ifndef TOR_TOKEN_BUCKET_H
@@ -11,52 +11,53 @@
#include "torint.h"
-typedef struct token_bucket_t {
+typedef struct token_bucket_rw_t {
uint32_t rate;
int32_t burst;
int32_t read_bucket;
int32_t write_bucket;
uint32_t last_refilled_at_ts;
-} token_bucket_t;
+} token_bucket_rw_t;
-#define TOKEN_BUCKET_MAX_BURST INT32_MAX
+#define TOKEN_BUCKET_RW_MAX_BURST INT32_MAX
-void token_bucket_init(token_bucket_t *bucket,
+void token_bucket_rw_init(token_bucket_rw_t *bucket,
uint32_t rate,
uint32_t burst,
uint32_t now_ts);
-void token_bucket_adjust(token_bucket_t *bucket,
+void token_bucket_rw_adjust(token_bucket_rw_t *bucket,
uint32_t rate, uint32_t burst);
-void token_bucket_reset(token_bucket_t *bucket,
+void token_bucket_rw_reset(token_bucket_rw_t *bucket,
uint32_t now_ts);
#define TB_READ 1
#define TB_WRITE 2
-int token_bucket_refill(token_bucket_t *bucket,
+int token_bucket_rw_refill(token_bucket_rw_t *bucket,
uint32_t now_ts);
-int token_bucket_dec_read(token_bucket_t *bucket,
+int token_bucket_rw_dec_read(token_bucket_rw_t *bucket,
ssize_t n);
-int token_bucket_dec_write(token_bucket_t *bucket,
+int token_bucket_rw_dec_write(token_bucket_rw_t *bucket,
ssize_t n);
-void token_bucket_dec(token_bucket_t *bucket,
+void token_bucket_rw_dec(token_bucket_rw_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_rw_get_read(const token_bucket_rw_t *bucket);
static inline size_t
-token_bucket_get_read(const token_bucket_t *bucket)
+token_bucket_rw_get_read(const token_bucket_rw_t *bucket)
{
const ssize_t b = bucket->read_bucket;
return b >= 0 ? b : 0;
}
-static inline size_t token_bucket_get_write(const token_bucket_t *bucket);
+static inline size_t token_bucket_rw_get_write(
+ const token_bucket_rw_t *bucket);
static inline size_t
-token_bucket_get_write(const token_bucket_t *bucket)
+token_bucket_rw_get_write(const token_bucket_rw_t *bucket)
{
const ssize_t b = bucket->write_bucket;
return b >= 0 ? b : 0;