summaryrefslogtreecommitdiff
path: root/hrtime.h
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2022-07-26 17:40:00 +0200
committerJean Boussier <jean.boussier@gmail.com>2022-08-02 11:04:28 +0200
commite3aabe93aae87a60ba7b8f1a0fd590534647e352 (patch)
tree3f5c15b61c9914c7e1a34ad56d042dcf70024f75 /hrtime.h
parentec3f59309e3f08339c4c76a6881901580801d6cd (diff)
downloadruby-e3aabe93aae87a60ba7b8f1a0fd590534647e352.tar.gz
Implement Queue#pop(timeout: sec)
[Feature #18774] As well as `SizedQueue#pop(timeout: sec)` If both `non_block=true` and `timeout:` are supplied, ArgumentError is raised.
Diffstat (limited to 'hrtime.h')
-rw-r--r--hrtime.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/hrtime.h b/hrtime.h
index 4ac3d54723..80aff5deb3 100644
--- a/hrtime.h
+++ b/hrtime.h
@@ -36,6 +36,7 @@
#define RB_HRTIME_PER_MSEC (RB_HRTIME_PER_USEC * (rb_hrtime_t)1000)
#define RB_HRTIME_PER_SEC (RB_HRTIME_PER_MSEC * (rb_hrtime_t)1000)
#define RB_HRTIME_MAX UINT64_MAX
+#define RB_HRTIME_MIN ((rb_hrtime_t)0)
/*
* Lets try to support time travelers. Lets assume anybody with a time machine
@@ -91,6 +92,15 @@ rb_hrtime_add(rb_hrtime_t a, rb_hrtime_t b)
return c;
}
+static inline rb_hrtime_t
+rb_hrtime_sub(rb_hrtime_t a, rb_hrtime_t b)
+{
+ if (a < b) {
+ return RB_HRTIME_MIN;
+ }
+ return a - b;
+}
+
/*
* convert a timeval struct to rb_hrtime_t, clamping at RB_HRTIME_MAX
*/