aboutsummaryrefslogtreecommitdiff
path: root/build2/scheduler.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-01-23 21:47:38 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-01-24 14:03:08 +0300
commitcc6280af7eca660c916dc652066216acd474979d (patch)
tree656eea184002c665ebb1c7385d1c560c2ea67249 /build2/scheduler.cxx
parent1a30ba3788022d9cbee8cd13ae065f927817a08b (diff)
Add testscript sleep builtin
Diffstat (limited to 'build2/scheduler.cxx')
-rw-r--r--build2/scheduler.cxx26
1 files changed, 26 insertions, 0 deletions
diff --git a/build2/scheduler.cxx b/build2/scheduler.cxx
index 2438d0b..053532e 100644
--- a/build2/scheduler.cxx
+++ b/build2/scheduler.cxx
@@ -11,6 +11,14 @@
# endif
#endif
+#ifndef _WIN32
+# include <thread> // this_thread::sleep_for()
+#else
+# include <libbutl/win32-utility.hxx>
+
+# include <chrono>
+#endif
+
#include <cerrno>
#include <exception> // std::terminate()
@@ -175,6 +183,24 @@ namespace build2
throw_generic_error (ECANCELED);
}
+ void scheduler::
+ sleep (const duration& d)
+ {
+ deactivate ();
+
+ // MINGW GCC 4.9 doesn't implement this_thread so use Win32 Sleep().
+ //
+#ifndef _WIN32
+ this_thread::sleep_for (d);
+#else
+ using namespace chrono;
+
+ Sleep (static_cast<DWORD> (duration_cast<milliseconds> (d).count ()));
+#endif
+
+ activate ();
+ }
+
size_t scheduler::
suspend (size_t start_count, const atomic_count& task_count)
{