]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ratelimit: add ratelimit_left helper
authorLuca Boccassi <bluca@debian.org>
Fri, 28 Apr 2023 12:10:23 +0000 (13:10 +0100)
committerLuca Boccassi <bluca@debian.org>
Fri, 19 May 2023 14:17:35 +0000 (15:17 +0100)
src/basic/ratelimit.c
src/basic/ratelimit.h

index 5675ec2f46bfea24ab7a537641aacc7c7b645d87..41ca0709e8e3788948539a1a83d2b845c401f6dd 100644 (file)
@@ -49,3 +49,12 @@ usec_t ratelimit_end(const RateLimit *rl) {
 
         return usec_add(rl->begin, rl->interval);
 }
+
+usec_t ratelimit_left(const RateLimit *rl) {
+        assert(rl);
+
+        if (rl->begin == 0)
+                return 0;
+
+        return usec_sub_unsigned(ratelimit_end(rl), now(CLOCK_MONOTONIC));
+}
index 048084ece49b42bebb765afb5e95bcc8f47a41ba..bb7160a895b9b3f55fb9fcff19b701c33844db78 100644 (file)
@@ -25,3 +25,4 @@ bool ratelimit_below(RateLimit *r);
 unsigned ratelimit_num_dropped(RateLimit *r);
 
 usec_t ratelimit_end(const RateLimit *rl);
+usec_t ratelimit_left(const RateLimit *rl);