File indexing completed on 2025-01-18 09:50:09
0001
0002
0003
0004
0005
0006 #ifndef BOOST_PROCESS_DETAIL_ON_EXIT_HPP_
0007 #define BOOST_PROCESS_DETAIL_ON_EXIT_HPP_
0008
0009 #include <boost/process/detail/config.hpp>
0010
0011 #if defined(BOOST_POSIX_API)
0012 #include <boost/process/detail/posix/on_exit.hpp>
0013 #elif defined(BOOST_WINDOWS_API)
0014 #include <boost/process/detail/windows/on_exit.hpp>
0015 #endif
0016
0017 #include <future>
0018 #include <memory>
0019
0020 namespace boost { namespace process { namespace detail {
0021
0022 inline std::function<void(int, const std::error_code &)> on_exit_from_future(std::future<int> &f)
0023 {
0024 std::shared_ptr<std::promise<int>> promise = std::make_shared<std::promise<int>>();
0025 f = promise->get_future();
0026 return [promise](int code, const std::error_code & ec)
0027 {
0028 if (ec)
0029 promise->set_exception(
0030 std::make_exception_ptr(process_error(ec, "on_exit failed with error"))
0031 );
0032 else
0033 promise->set_value(code);
0034 };
0035 }
0036
0037
0038 struct on_exit_
0039 {
0040 api::on_exit_ operator= (const std::function<void(int, const std::error_code&)> & f) const {return f;}
0041 api::on_exit_ operator()(const std::function<void(int, const std::error_code&)> & f) const {return f;}
0042
0043 api::on_exit_ operator= (std::future<int> &f) const {return on_exit_from_future(f);}
0044 api::on_exit_ operator()(std::future<int> &f) const {return on_exit_from_future(f);}
0045 };
0046
0047 }
0048
0049 constexpr static ::boost::process::detail::on_exit_ on_exit{};
0050
0051
0052 }}
0053 #endif