summaryrefslogtreecommitdiff
path: root/boost/process/detail/windows/wait_group.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/process/detail/windows/wait_group.hpp')
-rw-r--r--boost/process/detail/windows/wait_group.hpp94
1 files changed, 30 insertions, 64 deletions
diff --git a/boost/process/detail/windows/wait_group.hpp b/boost/process/detail/windows/wait_group.hpp
index e0b18b1268..32a8cd8842 100644
--- a/boost/process/detail/windows/wait_group.hpp
+++ b/boost/process/detail/windows/wait_group.hpp
@@ -9,20 +9,12 @@
#include <boost/process/detail/config.hpp>
#include <boost/winapi/jobs.hpp>
#include <boost/winapi/wait.hpp>
-
+#include <chrono>
namespace boost { namespace process { namespace detail { namespace windows {
struct group_handle;
-inline void wait(const group_handle &p)
-{
- if (::boost::winapi::WaitForSingleObject(p.handle(),
- ::boost::winapi::infinite) == ::boost::winapi::wait_failed)
- throw_last_error("WaitForSingleObject() failed");
-
-}
-
inline void wait(const group_handle &p, std::error_code &ec)
{
if (::boost::winapi::WaitForSingleObject(p.handle(),
@@ -30,38 +22,26 @@ inline void wait(const group_handle &p, std::error_code &ec)
ec = get_last_error();
}
-
-template< class Rep, class Period >
-inline bool wait_for(
- const group_handle &p,
- const std::chrono::duration<Rep, Period>& rel_time)
+inline void wait(const group_handle &p)
{
-
- std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(rel_time);
-
- ::boost::winapi::DWORD_ wait_code;
- wait_code = ::boost::winapi::WaitForSingleObject(p.handle(), ms.count());
- if (wait_code == ::boost::winapi::wait_failed)
- throw_last_error("WaitForSingleObject() failed");
- else if (wait_code == ::boost::winapi::wait_timeout)
- return false; //
-
- return true;
+ std::error_code ec;
+ wait(p, ec);
+ boost::process::detail::throw_error(ec, "wait error");
}
-
-template< class Rep, class Period >
-inline bool wait_for(
+template< class Clock, class Duration >
+inline bool wait_until(
const group_handle &p,
- const std::chrono::duration<Rep, Period>& rel_time,
+ const std::chrono::time_point<Clock, Duration>& timeout_time,
std::error_code &ec)
{
-
- std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(rel_time);
-
+ std::chrono::milliseconds ms =
+ std::chrono::duration_cast<std::chrono::milliseconds>(
+ timeout_time - Clock::now());
::boost::winapi::DWORD_ wait_code;
wait_code = ::boost::winapi::WaitForSingleObject(p.handle(), ms.count());
+
if (wait_code == ::boost::winapi::wait_failed)
ec = get_last_error();
@@ -76,44 +56,30 @@ inline bool wait_until(
const group_handle &p,
const std::chrono::time_point<Clock, Duration>& timeout_time)
{
- std::chrono::milliseconds ms =
- std::chrono::duration_cast<std::chrono::milliseconds>(
- timeout_time - std::chrono::system_clock::now());
-
- ::boost::winapi::DWORD_ wait_code;
- wait_code = ::boost::winapi::WaitForSingleObject(p.handle(), ms.count());
-
- if (wait_code == ::boost::winapi::wait_failed)
- throw_last_error("WaitForSingleObject() failed");
-
- else if (wait_code == ::boost::winapi::wait_timeout)
- return false; //
-
- return true;
+ std::error_code ec;
+ bool b = wait_until(p, timeout_time, ec);
+ boost::process::detail::throw_error(ec, "wait_until error");
+ return b;
}
-
-template< class Clock, class Duration >
-inline bool wait_until(
+template< class Rep, class Period >
+inline bool wait_for(
const group_handle &p,
- const std::chrono::time_point<Clock, Duration>& timeout_time,
+ const std::chrono::duration<Rep, Period>& rel_time,
std::error_code &ec)
{
- std::chrono::milliseconds ms =
- std::chrono::duration_cast<std::chrono::milliseconds>(
- timeout_time - std::chrono::system_clock::now());
-
- ::boost::winapi::DWORD_ wait_code;
- wait_code = ::boost::winapi::WaitForSingleObject(p.handle(), ms.count());
-
- if (wait_code == ::boost::winapi::wait_failed)
- ec = get_last_error();
-
- else if (wait_code == ::boost::winapi::wait_timeout)
- return false; //
+ return wait_until(p, std::chrono::steady_clock::now() + rel_time, ec);
+}
- return true;
-;
+template< class Rep, class Period >
+inline bool wait_for(
+ const group_handle &p,
+ const std::chrono::duration<Rep, Period>& rel_time)
+{
+ std::error_code ec;
+ bool b = wait_for(p, rel_time, ec);
+ boost::process::detail::throw_error(ec, "wait_for error");
+ return b;
}
}}}}