diff options
author | Nick Mathewson <nickm@torproject.org> | 2010-09-14 22:32:36 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2010-09-14 22:32:36 -0400 |
commit | 6d8fc4eb3866122ef42f209cc51a875a3e438607 (patch) | |
tree | 89190e195c05359882d3ce2fbc282419eaa6d928 | |
parent | 60e3def3ed7428b139cfd6e36517f930a84bd085 (diff) | |
download | tor-6d8fc4eb3866122ef42f209cc51a875a3e438607.tar.gz tor-6d8fc4eb3866122ef42f209cc51a875a3e438607.zip |
Add a simple integer-ceiling-division macro before we get it wrong
-rw-r--r-- | src/common/util.h | 5 | ||||
-rw-r--r-- | src/or/connection_or.c | 3 | ||||
-rw-r--r-- | src/or/relay.c | 3 | ||||
-rw-r--r-- | src/or/routerlist.c | 4 |
4 files changed, 9 insertions, 6 deletions
diff --git a/src/common/util.h b/src/common/util.h index 3a3a87378a..4a31c277e3 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -160,6 +160,11 @@ unsigned round_to_next_multiple_of(unsigned number, unsigned divisor); uint32_t round_uint32_to_next_multiple_of(uint32_t number, uint32_t divisor); uint64_t round_uint64_to_next_multiple_of(uint64_t number, uint64_t divisor); +/* Compute the CEIL of <b>a</b> divided by <b>b</b>, for nonnegative <b>a</b> + * and positive <b>b</b>. Works on integer types only. Not defined if a+b can + * overflow. */ +#define CEIL_DIV(a,b) (((a)+(b)-1)/(b)) + /* String manipulation */ /** Allowable characters in a hexadecimal string. */ diff --git a/src/or/connection_or.c b/src/or/connection_or.c index 0ba1bca31f..686037f2de 100644 --- a/src/or/connection_or.c +++ b/src/or/connection_or.c @@ -252,8 +252,7 @@ connection_or_flushed_some(or_connection_t *conn) /* If we're under the low water mark, add cells until we're just over the * high water mark. */ if (datalen < OR_CONN_LOWWATER) { - ssize_t n = (OR_CONN_HIGHWATER - datalen + CELL_NETWORK_SIZE-1) - / CELL_NETWORK_SIZE; + ssize_t n = CEIL_DIV(OR_CONN_HIGHWATER - datalen, CELL_NETWORK_SIZE); time_t now = approx_time(); while (conn->active_circuits && n > 0) { int flushed; diff --git a/src/or/relay.c b/src/or/relay.c index 125b2f78e2..935fad9200 100644 --- a/src/or/relay.c +++ b/src/or/relay.c @@ -1520,8 +1520,7 @@ circuit_resume_edge_reading_helper(edge_connection_t *first_conn, again: - /* ??? turn this into a ceildiv function? */ - cells_per_conn = (max_to_package + n_streams - 1 ) / n_streams; + cells_per_conn = CEIL_DIV(max_to_package, n_streams); packaged_this_round = 0; n_streams_left = 0; diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 480da44ba6..b77107ca0b 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -4220,7 +4220,7 @@ launch_router_descriptor_downloads(smartlist_t *downloadable, pds_flags |= PDS_NO_EXISTING_SERVERDESC_FETCH; } - n_per_request = (n_downloadable+MIN_REQUESTS-1) / MIN_REQUESTS; + n_per_request = CEIL_DIV(n_downloadable, MIN_REQUESTS); if (n_per_request > MAX_DL_PER_REQUEST) n_per_request = MAX_DL_PER_REQUEST; if (n_per_request < MIN_DL_PER_REQUEST) @@ -4233,7 +4233,7 @@ launch_router_descriptor_downloads(smartlist_t *downloadable, log_info(LD_DIR, "Launching %d request%s for %d router%s, %d at a time", - (n_downloadable+n_per_request-1)/n_per_request, + CEIL_DIV(n_downloadable, n_per_request), req_plural, n_downloadable, rtr_plural, n_per_request); smartlist_sort_digests(downloadable); for (i=0; i < n_downloadable; i += n_per_request) { |