From 3388e09cbb920fc3b904327f3b254f794e231ed1 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 13 Jun 2018 23:20:16 +0200 Subject: [PATCH] snake_case xbt/functional.hpp --- include/simgrid/kernel/future.hpp | 19 ++++++++----------- include/simgrid/s4u/Actor.hpp | 3 +-- include/xbt/functional.hpp | 31 ++++++++++++++++++++++++------- src/msg/msg_process.cpp | 2 +- src/simix/ActorImpl.cpp | 2 +- src/simix/smx_deployment.cpp | 4 +--- src/simix/smx_global.cpp | 2 +- 7 files changed, 37 insertions(+), 26 deletions(-) diff --git a/include/simgrid/kernel/future.hpp b/include/simgrid/kernel/future.hpp index e779c0ad63..6adfe664dd 100644 --- a/include/simgrid/kernel/future.hpp +++ b/include/simgrid/kernel/future.hpp @@ -327,8 +327,7 @@ public: throw std::future_error(std::future_errc::no_state); // Give shared-ownership to the continuation: auto state = std::move(state_); - state->set_continuation(simgrid::xbt::makeTask( - std::move(continuation), state)); + state->set_continuation(simgrid::xbt::make_task(std::move(continuation), state)); } /** Attach a continuation to this future @@ -347,15 +346,13 @@ public: Promise promise; Future future = promise.get_future(); // ...and when the current future is ready... - state->set_continuation(simgrid::xbt::makeTask( - [](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)); - }); - }, - std::move(promise), state, std::move(continuation))); + state->set_continuation(simgrid::xbt::make_task( + [](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)); }); + }, + std::move(promise), state, std::move(continuation))); return std::move(future); } diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index bbe2e73900..e1bcbac22f 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -132,8 +132,7 @@ class XBT_PUBLIC Actor : public simgrid::xbt::Extendable { static std::function wrap_task(F f, Args... args) { typedef decltype(f(std::move(args)...)) R; - auto task = std::make_shared>( - simgrid::xbt::makeTask(std::move(f), std::move(args)...)); + auto task = std::make_shared>(simgrid::xbt::make_task(std::move(f), std::move(args)...)); return [task] { (*task)(); }; } diff --git a/include/xbt/functional.hpp b/include/xbt/functional.hpp index 1c6983a120..4b5f0afc10 100644 --- a/include/xbt/functional.hpp +++ b/include/xbt/functional.hpp @@ -52,14 +52,26 @@ public: } }; -template inline -std::function wrapMain(F code, std::vector args) +template +inline XBT_ATTRIB_DEPRECATED_v323("Please use wrap_main()") std::function wrapMain( + F code, std::vector args) { return MainFunction(std::move(code), std::move(args)); } -template inline -std::function wrapMain(F code, int argc, const char*const argv[]) +template inline std::function wrap_main(F code, std::vector args) +{ + return MainFunction(std::move(code), std::move(args)); +} + +template +inline XBT_ATTRIB_DEPRECATED_v323("Please use wrap_main()") std::function wrapMain(F code, int argc, + const char* const argv[]) +{ + std::vector args(argv, argv + argc); + return MainFunction(std::move(code), std::move(args)); +} +template inline std::function wrap_main(F code, int argc, const char* const argv[]) { std::vector args(argv, argv + argc); return MainFunction(std::move(code), std::move(args)); @@ -288,14 +300,19 @@ public: } }; -template -auto makeTask(F code, Args... args) --> Task< decltype(code(std::move(args)...))() > +template +XBT_ATTRIB_DEPRECATED_v323("Please use make_task()") auto makeTask(F code, Args... args) + -> Task { TaskImpl task(std::move(code), std::make_tuple(std::move(args)...)); return Task(std::move(task)); } +template auto make_task(F code, Args... args) -> Task +{ + TaskImpl task(std::move(code), std::make_tuple(std::move(args)...)); + return Task(std::move(task)); +} } } diff --git a/src/msg/msg_process.cpp b/src/msg/msg_process.cpp index 51ea774272..521170a2ef 100644 --- a/src/msg/msg_process.cpp +++ b/src/msg/msg_process.cpp @@ -129,7 +129,7 @@ msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_fun { std::function function; if (code) - function = simgrid::xbt::wrapMain(code, argc, static_cast(argv)); + function = simgrid::xbt::wrap_main(code, argc, static_cast(argv)); std::unordered_map props; xbt_dict_cursor_t cursor = nullptr; diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index b2603b8b87..e45266f06b 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -802,7 +802,7 @@ smx_actor_t simcall_process_create(const char* name, xbt_main_func_t code, void* { if (name == nullptr) name = ""; - auto wrapped_code = simgrid::xbt::wrapMain(code, argc, argv); + auto wrapped_code = simgrid::xbt::wrap_main(code, argc, argv); for (int i = 0; i != argc; ++i) xbt_free(argv[i]); xbt_free(argv); diff --git a/src/simix/smx_deployment.cpp b/src/simix/smx_deployment.cpp index 8e11f4aad8..79a4993317 100644 --- a/src/simix/smx_deployment.cpp +++ b/src/simix/smx_deployment.cpp @@ -58,9 +58,7 @@ void SIMIX_launch_application(const char *file) // Wrap a main() function into a ActorCodeFactory: static simgrid::simix::ActorCodeFactory toActorCodeFactory(xbt_main_func_t code) { - return [code](std::vector args) { - return simgrid::xbt::wrapMain(code, std::move(args)); - }; + return [code](std::vector args) { return simgrid::xbt::wrap_main(code, std::move(args)); }; } /** diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index 4f05ede58c..997394599c 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -562,7 +562,7 @@ void SIMIX_run() */ smx_timer_t SIMIX_timer_set(double date, void (*callback)(void*), void *arg) { - smx_timer_t timer = new s_smx_timer_t(date, simgrid::xbt::makeTask([callback, arg]() { callback(arg); })); + smx_timer_t timer = new s_smx_timer_t(date, simgrid::xbt::make_task([callback, arg]() { callback(arg); })); timer->handle_ = simix_timers.emplace(std::make_pair(date, timer)); return timer; } -- 2.20.1