aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/script/timeout.ixx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-10-10 17:22:46 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-11-06 19:32:09 +0300
commitf41599c8e9435f3dfec60b872c2b4ae31177efdd (patch)
tree088f8d9bf906e4a2ed734e034699163c9ccc7306 /libbuild2/script/timeout.ixx
parentac76a4fd2afff48a0d5db84592babe5cabef3a2c (diff)
Add support for test timeouts
Diffstat (limited to 'libbuild2/script/timeout.ixx')
-rw-r--r--libbuild2/script/timeout.ixx44
1 files changed, 44 insertions, 0 deletions
diff --git a/libbuild2/script/timeout.ixx b/libbuild2/script/timeout.ixx
new file mode 100644
index 0000000..755af17
--- /dev/null
+++ b/libbuild2/script/timeout.ixx
@@ -0,0 +1,44 @@
+// file : libbuild2/script/timeout.ixx -*- C++ -*-
+// license : MIT; see accompanying LICENSE file
+
+namespace build2
+{
+ inline optional<timestamp>
+ parse_deadline (const string& s, const char* what, const location& l)
+ {
+ if (optional<duration> t = parse_timeout (s, what, l))
+ return system_clock::now () + *t;
+ else
+ return nullopt;
+ }
+
+ template <typename T>
+ inline T
+ earlier (const T& x, const T& y)
+ {
+ return x < y ? x : y;
+ }
+
+ template <typename T>
+ inline T
+ earlier (const T& x, const optional<T>& y)
+ {
+ return y ? earlier (x, *y) : x;
+ }
+
+ template <typename T>
+ inline T
+ earlier (const optional<T>& x, const T& y)
+ {
+ return earlier (y, x);
+ }
+
+ template <typename T>
+ inline optional<T>
+ earlier (const optional<T>& x, const optional<T>& y)
+ {
+ return x ? earlier (*x, y) :
+ y ? earlier (*y, x) :
+ optional<T> ();
+ }
+}