aboutsummaryrefslogtreecommitdiff
path: root/build2/test/script/builtin.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-03-23 21:40:04 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-03-23 21:40:04 +0200
commit9ff6adf13f4176230e39685b9035f176360f712f (patch)
tree2dc97080e673a0b666c5ab771c5de0e09135dddf /build2/test/script/builtin.cxx
parenta291d146c1c730510ca3e6b4ecae6c4694dad2cd (diff)
Reimplement testscript builtins without thread detach, future/promise
Diffstat (limited to 'build2/test/script/builtin.cxx')
-rw-r--r--build2/test/script/builtin.cxx62
1 files changed, 24 insertions, 38 deletions
diff --git a/build2/test/script/builtin.cxx b/build2/test/script/builtin.cxx
index 3305c3a..d96058e 100644
--- a/build2/test/script/builtin.cxx
+++ b/build2/test/script/builtin.cxx
@@ -11,7 +11,6 @@
#endif
#include <locale>
-#include <thread>
#include <ostream>
#include <sstream>
@@ -43,14 +42,6 @@ namespace build2
using builtin_impl = uint8_t (scope&,
const strings& args,
auto_fd in, auto_fd out, auto_fd err);
- static future<uint8_t>
- to_future (uint8_t status)
- {
- promise<uint8_t> p;
- future<uint8_t> f (p.get_future ());
- p.set_value (status);
- return f;
- }
// Operation failed, diagnostics has already been issued.
//
@@ -521,10 +512,10 @@ namespace build2
//
// Note: can be executed synchronously.
//
- static future<uint8_t>
- false_ (scope&, const strings&, auto_fd, auto_fd, auto_fd)
+ static builtin
+ false_ (scope&, uint8_t& r, const strings&, auto_fd, auto_fd, auto_fd)
{
- return to_future (1);
+ return builtin (r = 1);
}
// true
@@ -533,10 +524,10 @@ namespace build2
//
// Note: can be executed synchronously.
//
- static future<uint8_t>
- true_ (scope&, const strings&, auto_fd, auto_fd, auto_fd)
+ static builtin
+ true_ (scope&, uint8_t& r, const strings&, auto_fd, auto_fd, auto_fd)
{
- return to_future (0);
+ return builtin (r = 0);
}
// Create a directory if not exist and its parent directories if
@@ -1362,15 +1353,11 @@ namespace build2
scope& sp,
const strings& args,
auto_fd in, auto_fd out, auto_fd err,
- promise<uint8_t> p) noexcept
+ uint8_t& r) noexcept
{
try
{
- // The use of set_value_at_thread_exit() would be more appropriate
- // but the function is not supported by old versions of g++ (e.g.,
- // not in 4.9). There could also be overhead associated with it.
- //
- p.set_value (fn (sp, args, move (in), move (out), move (err)));
+ r = fn (sp, args, move (in), move (out), move (err));
}
catch (const std::exception& e)
{
@@ -1382,44 +1369,43 @@ namespace build2
// Run builtin implementation asynchronously.
//
- static future<uint8_t>
+ static builtin
async_impl (builtin_impl fn,
scope& sp,
+ uint8_t& r,
const strings& args,
auto_fd in, auto_fd out, auto_fd err)
{
- promise<uint8_t> p;
- future<uint8_t> f (p.get_future ());
-
- thread t (thread_thunk,
- fn,
- ref (sp),
- cref (args),
- move (in), move (out), move (err),
- move (p));
-
- t.detach ();
- return f;
+ return builtin (r,
+ thread (thread_thunk,
+ fn,
+ ref (sp),
+ cref (args),
+ move (in), move (out), move (err),
+ ref (r)));
}
template <builtin_impl fn>
- static future<uint8_t>
+ static builtin
async_impl (scope& sp,
+ uint8_t& r,
const strings& args,
auto_fd in, auto_fd out, auto_fd err)
{
- return async_impl (fn, sp, args, move (in), move (out), move (err));
+ return async_impl (fn, sp, r, args, move (in), move (out), move (err));
}
// Run builtin implementation synchronously.
//
template <builtin_impl fn>
- static future<uint8_t>
+ static builtin
sync_impl (scope& sp,
+ uint8_t& r,
const strings& args,
auto_fd in, auto_fd out, auto_fd err)
{
- return to_future (fn (sp, args, move (in), move (out), move (err)));
+ r = fn (sp, args, move (in), move (out), move (err));
+ return builtin (r, thread ());
}
const builtin_map builtins