From 9ff6adf13f4176230e39685b9035f176360f712f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 23 Mar 2017 21:40:04 +0200 Subject: Reimplement testscript builtins without thread detach, future/promise --- build2/test/script/builtin | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'build2/test/script/builtin') diff --git a/build2/test/script/builtin b/build2/test/script/builtin index 226a0e0..7d902ea 100644 --- a/build2/test/script/builtin +++ b/build2/test/script/builtin @@ -18,26 +18,48 @@ namespace build2 { class scope; + // A process/thread-like object representing a running builtin. + // + // For now, instead of allocating the result storage dynamically, we + // expect it to be provided by the caller. + // + class builtin + { + public: + uint8_t + wait () {if (t_.joinable ()) t_.join (); return r_;} + + ~builtin () {wait ();} + + public: + builtin (uint8_t& r, thread&& t = thread ()): r_ (r), t_ (move (t)) {} + + builtin (builtin&&) = default; + builtin& operator= (builtin&&) = default; + + private: + uint8_t& r_; + thread t_; + }; + // Start builtin command. Throw system_error on failure. // // Note that unlike argc/argv, our args don't include the program name. // - // Also note that the future object being returned doesn't block in dtor - // until the builtin command terminates. - // - using builtin = future (scope&, - const strings& args, - auto_fd in, auto_fd out, auto_fd err); + using builtin_func = builtin (scope&, + uint8_t& result, + const strings& args, + auto_fd in, auto_fd out, auto_fd err); - class builtin_map: public std::map + class builtin_map: public std::map { public: - using base = std::map; + using base = std::map; using base::base; // Return NULL if not a builtin. // - builtin* + builtin_func* find (const string& n) const { auto i (base::find (n)); -- cgit v1.1