From 3bd0ffd5e6dd32ddf61c69456b490f2aa9f2517b Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sat, 16 Jun 2018 09:13:27 +0200 Subject: [PATCH] snake_case xbt/future.hpp --- include/simgrid/kernel/future.hpp | 8 ++--- include/simgrid/simix.hpp | 4 +-- include/simgrid/simix/blocking_simcall.hpp | 4 +-- include/xbt/future.hpp | 39 +++++++++++++++++----- src/surf/sg_platf.cpp | 4 +-- 5 files changed, 38 insertions(+), 21 deletions(-) diff --git a/include/simgrid/kernel/future.hpp b/include/simgrid/kernel/future.hpp index 6adfe664dd..bc45b509b5 100644 --- a/include/simgrid/kernel/future.hpp +++ b/include/simgrid/kernel/future.hpp @@ -210,10 +210,8 @@ void bindPromise(Promise promise, Future future) class PromiseBinder { public: explicit PromiseBinder(Promise promise) : promise_(std::move(promise)) {} - void operator()(Future future) - { - simgrid::xbt::setPromise(promise_, future); - } + void operator()(Future future) { simgrid::xbt::set_promise(promise_, future); } + private: Promise promise_; }; @@ -350,7 +348,7 @@ public: [](Promise promise, std::shared_ptr> state, F continuation) { // ...set the new future value by running the continuation. Future future(std::move(state)); - simgrid::xbt::fulfillPromise(promise, [&] { return continuation(std::move(future)); }); + simgrid::xbt::fulfill_promise(promise, [&] { return continuation(std::move(future)); }); }, std::move(promise), state, std::move(continuation))); return std::move(future); diff --git a/include/simgrid/simix.hpp b/include/simgrid/simix.hpp index 9943239d5c..d6731a9fe4 100644 --- a/include/simgrid/simix.hpp +++ b/include/simgrid/simix.hpp @@ -61,9 +61,7 @@ template typename std::result_of::type simcall(F&& code) // conveniently handles the success/failure value for us. typedef typename std::result_of::type R; simgrid::xbt::Result result; - simcall_run_kernel([&]{ - simgrid::xbt::fulfillPromise(result, std::forward(code)); - }); + simcall_run_kernel([&] { simgrid::xbt::fulfill_promise(result, std::forward(code)); }); return result.get(); } diff --git a/include/simgrid/simix/blocking_simcall.hpp b/include/simgrid/simix/blocking_simcall.hpp index dcc7b1d87c..2a93bf2364 100644 --- a/include/simgrid/simix/blocking_simcall.hpp +++ b/include/simgrid/simix/blocking_simcall.hpp @@ -60,7 +60,7 @@ auto kernelSync(F code) -> decltype(code().get()) try { auto future = code(); future.then_([&result, self](std::shared_ptr>&& value) { - simgrid::xbt::setPromise(result, simgrid::kernel::Future(value)); + simgrid::xbt::set_promise(result, simgrid::kernel::Future(value)); simgrid::simix::unblock(self); }); } @@ -96,7 +96,7 @@ public: // When the kernel future is ready... this->future_.then_([&result, self](std::shared_ptr>&& value) { // ... wake up the process with the result of the kernel future. - simgrid::xbt::setPromise(result, simgrid::kernel::Future(value)); + simgrid::xbt::set_promise(result, simgrid::kernel::Future(value)); simgrid::simix::unblock(self); }); } diff --git a/include/xbt/future.hpp b/include/xbt/future.hpp index 3c1f761ab7..be488ed9d7 100644 --- a/include/xbt/future.hpp +++ b/include/xbt/future.hpp @@ -199,9 +199,17 @@ public: * @param code What we want to do * @param promise Where to want to store the result */ -template -auto fulfillPromise(R& promise, F&& code) --> decltype(promise.set_value(code())) +template auto fulfill_promise(R& promise, F&& code) -> decltype(promise.set_value(code())) +{ + try { + promise.set_value(std::forward(code)()); + } catch (...) { + promise.set_exception(std::current_exception()); + } +} +template +XBT_ATTRIB_DEPRECATED_v323("Please use xbt::fulfill_promise()") auto fulfillPromise(R& promise, F&& code) + -> decltype(promise.set_value(code())) { try { promise.set_value(std::forward(code)()); @@ -211,9 +219,18 @@ auto fulfillPromise(R& promise, F&& code) } } -template -auto fulfillPromise(P& promise, F&& code) --> decltype(promise.set_value()) +template auto fulfill_promise(P& promise, F&& code) -> decltype(promise.set_value()) +{ + try { + std::forward(code)(); + promise.set_value(); + } catch (...) { + promise.set_exception(std::current_exception()); + } +} +template +XBT_ATTRIB_DEPRECATED_v323("Please use xbt::fulfill_promise()") auto fulfillPromise(P& promise, F&& code) + -> decltype(promise.set_value()) { try { std::forward(code)(); @@ -238,10 +255,14 @@ auto fulfillPromise(P& promise, F&& code) * @param promise output (a valid future or a result) * @param future input (a ready/waitable future or a valid result) */ -template inline -void setPromise(P& promise, F&& future) +template inline void set_promise(P& promise, F&& future) +{ + fulfill_promise(promise, [&] { return std::forward(future).get(); }); +} +template +inline XBT_ATTRIB_DEPRECATED_v323("Please use xbt::set_promise()") void setPromise(P& promise, F&& future) { - fulfillPromise(promise, [&]{ return std::forward(future).get(); }); + fulfill_promise(promise, [&] { return std::forward(future).get(); }); } } diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 24def5ed79..5df6412412 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -54,8 +54,8 @@ void sg_platf_init() /** Module management function: frees all internal data structures */ void sg_platf_exit() { - simgrid::surf::on_cluster.disconnectSlots(); - simgrid::s4u::on_platform_created.disconnectSlots(); + simgrid::surf::on_cluster.disconnect_slots(); + simgrid::s4u::on_platform_created.disconnect_slots(); /* make sure that we will reinit the models while loading the platf once reinited */ surf_parse_models_setup_already_called = 0; -- 2.20.1