From 8a76210661702035825e159d5d84ab784d2cbd57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Fri, 11 Oct 2013 23:54:37 +0200 Subject: [PATCH] Comment rate_limit.h --- include/ucore/rate_limit.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/ucore/rate_limit.h b/include/ucore/rate_limit.h index fa7ec01..51c70b4 100644 --- a/include/ucore/rate_limit.h +++ b/include/ucore/rate_limit.h @@ -62,8 +62,35 @@ struct RateLimit { long last_ts; }; +/** + * Initialize a struct RateLimit, which can hand out @tickets per @period + * the perioid must be in the same units as the current_ts + * + * @param r RateLimit to initialize + * @param tickets number of tickets (bucket depth) + * @param period per this period + * @param current_ts the current timestamp + */ void uc_ratelimit_init(struct RateLimit *r, long tickets, long period, long current_ts); + +/** + * Reset a RateLimit, filling up the tickets again. + * + * @param r RateLimit to reset + * @param current ts, if non-zero, re-sets the last_ts to the current_ts + */ void uc_ratelimit_reset(struct RateLimit *r, long current_ts); + +/** + * Check if we have 1 ticket available, and can therefore allow + * the work. Removes 1 ticket if we can, and replenishes the tickets + * based on the elapsed time since last time the function was called. + * + * @param r the RateLimit + * @param current_ts the current timestamp. Used to calculate the + * replenisment of tichets since the previous check. + * @return 1 if we can allow, 0 if we don't. + */ int uc_ratelimit_allow(struct RateLimit *r, long current_ts); #endif