From: Martin Quinson Date: Sat, 16 Jun 2018 21:26:32 +0000 (+0200) Subject: snake_case simix/blocking_simcall.hpp X-Git-Tag: v3.20~91 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/dfc3b7c81f7e4fec5c8da96745042766dc0da27f snake_case simix/blocking_simcall.hpp --- diff --git a/doc/doxygen/inside_extending.doc b/doc/doxygen/inside_extending.doc index e13c61cea6..a1f1286e1f 100644 --- a/doc/doxygen/inside_extending.doc +++ b/doc/doxygen/inside_extending.doc @@ -201,7 +201,7 @@ If there is no blocking and no mutation involved (getters), you might consider avoiding switching to Maestro and reading directly the data you're interested in. -For simcalls which might block, `kernelSync()` can be used. It takes a +For simcalls which might block, `kernel_sync()` can be used. It takes a C++ callback and executes it immediately in maestro. This C++ callback is expected to return a `simgrid::kernel::Future` reprensenting the operation in the kernal. When the operations completes, the user process is waken up @@ -209,25 +209,25 @@ with the result: ~~~ try { - std::vector result = simgrid::simix::kernelSync([&] { + std::vector result = simgrid::simix::kernel_sync([&] { // Fictional example, simgrid::kernel::readFile does not exist. simgrid::kernel::Future> result = simgrid::kernel::readFile(file); return result; }); XBT_DEBUG("Finished reading file %s: length %zu", file, result.size()); } -// If the operation failed, kernelSync() throws an exception: +// If the operation failed, kernel_sync() throws an exception: catch (std::runtime_error& e) { XBT_ERROR("Could not read file %s", file); } ~~~ -Asynchronous blocks can be implemented with `kernelAsync()`. It works -like `kernelSync()` but does not block. Instead, it returns a +Asynchronous blocks can be implemented with `kernel_async()`. It works +like `kernel_sync()` but does not block. Instead, it returns a `simgrid::simix::Future` representing the operation in the process: ~~~ -simgrid::simix::Future> result = simgrid::simix::kernelSync([&] { +simgrid::simix::Future> result = simgrid::simix::kernel_sync([&] { // Fictional example, simgrid::kernel::readFile does not exist. simgrid::kernek::Future> result = simgrid::kernel::readFile(file); return result; @@ -249,7 +249,7 @@ catch (std::runtime_error& e) { } ~~~ -Note: `kernelSync(f)` could be implemented as `kernelAsync(f).get()`. +Note: `kernel_sync(f)` could be implemented as `kernel_async(f).get()`. \section simgrid_dev_guide_tag What is How to add a new tag for xml files? diff --git a/doc/doxygen/uhood_switch.doc b/doc/doxygen/uhood_switch.doc index ac1b6faa0c..7247341ac1 100644 --- a/doc/doxygen/uhood_switch.doc +++ b/doc/doxygen/uhood_switch.doc @@ -468,14 +468,14 @@ kernel which will wake up the actor (with `simgrid::simix::unblock(actor)`) when the operation is completed. This is wrapped in a higher-level primitive as well. The -`kernelSync()` function expects a function-object which is executed +`kernel_sync()` function expects a function-object which is executed immediately in the simulation kernel and returns a `Future`. The simulator blocks the actor and resumes it when the `Future` becomes ready with its result: @code{cpp} template -auto kernelSync(F code) -> decltype(code().get()) +auto kernel_sync(F code) -> decltype(code().get()) { typedef decltype(code().get()) T; if (SIMIX_is_maestro()) @@ -510,7 +510,7 @@ auto kernelSync(F code) -> decltype(code().get()) A contrived example of this would be: @code{cpp} -int res = simgrid::simix::kernelSync([&] { +int res = simgrid::simix::kernel_sync([&] { return kernel_wait_until(30).then( [](simgrid::kernel::Future future) { return 42; @@ -521,7 +521,7 @@ int res = simgrid::simix::kernelSync([&] { ### Asynchronous operations {#uhood_switch_v2_async} -We can write the related `kernelAsync()` which wakes up the actor immediately +We can write the related `kernel_async()` which wakes up the actor immediately and returns a future to the actor. As this future is used in the actor context, it is a different future (`simgrid::simix::Future` instead of `simgrid::kernel::Future`) @@ -572,12 +572,12 @@ T simgrid::simix::Future::get() } @endcode -`kernelAsync()` simply :wink: calls `kernelImmediate()` and wraps the +`kernel_async()` simply :wink: calls `kernelImmediate()` and wraps the `simgrid::kernel::Future` into a `simgrid::simix::Future`: @code{cpp} template -auto kernelAsync(F code) +auto kernel_async(F code) -> Future { typedef decltype(code().get()) T; @@ -594,7 +594,7 @@ auto kernelAsync(F code) A contrived example of this would be: @code{cpp} -simgrid::simix::Future future = simgrid::simix::kernelSync([&] { +simgrid::simix::Future future = simgrid::simix::kernel_sync([&] { return kernel_wait_until(30).then( [](simgrid::kernel::Future future) { return 42; @@ -605,18 +605,18 @@ do_some_stuff(); int res = future.get(); @endcode -`kernelSync()` could be rewritten as: +`kernel_sync()` could be rewritten as: @code{cpp} template -auto kernelSync(F code) -> decltype(code().get()) +auto kernel_sync(F code) -> decltype(code().get()) { - return kernelAsync(std::move(code)).get(); + return kernel_async(std::move(code)).get(); } @endcode The semantic is equivalent but this form would require two simcalls -instead of one to do the same job (one in `kernelAsync()` and one in +instead of one to do the same job (one in `kernel_async()` and one in `.get()`). ## Mutexes and condition variables @@ -769,7 +769,7 @@ We wrote two future implementations based on the `std::future` API: * the second one is a wait-based (`future.get()`) future used in the actors which waits using a simcall. -These futures are used to implement `kernelSync()` and `kernelAsync()` which +These futures are used to implement `kernel_sync()` and `kernel_async()` which expose asynchronous operations in the simulation kernel to the actors. In addition, we wrote variations of some other C++ standard library diff --git a/include/simgrid/simix/blocking_simcall.hpp b/include/simgrid/simix/blocking_simcall.hpp index 2a93bf2364..d2c87daeec 100644 --- a/include/simgrid/simix/blocking_simcall.hpp +++ b/include/simgrid/simix/blocking_simcall.hpp @@ -46,8 +46,7 @@ XBT_PUBLIC void unblock(smx_actor_t process); * @return Value of the kernel future * @exception Exception from the kernel future */ -template -auto kernelSync(F code) -> decltype(code().get()) +template auto kernel_sync(F code) -> decltype(code().get()) { typedef decltype(code().get()) T; if (SIMIX_is_maestro()) @@ -71,6 +70,11 @@ auto kernelSync(F code) -> decltype(code().get()) }); return result.get(); } +template +XBT_ATTRIB_DEPRECATED_v323("Please use simix::kernel_sync()") auto kernelSync(F code) -> decltype(code().get()) +{ + return kernel_sync(code); +} /** A blocking (`wait()`-based) future for SIMIX processes */ // TODO, .wait_for() @@ -146,9 +150,7 @@ private: * @param code SimGrid kernel code which returns a simgrid::kernel::Future * @return Actor future */ -template -auto kernelAsync(F code) - -> Future +template auto kernel_async(F code) -> Future { typedef decltype(code().get()) T; @@ -158,7 +160,11 @@ auto kernelAsync(F code) // Wrap the kernel future in a actor future: return simgrid::simix::Future(std::move(future)); } - +template +XBT_ATTRIB_DEPRECATED_v323("Please use simix::kernel_sync()") auto kernelAsync(F code) -> Future +{ + return kernel_async(code); +} } } diff --git a/teshsuite/simix/generic-simcalls/generic-simcalls.cpp b/teshsuite/simix/generic-simcalls/generic-simcalls.cpp index 8e9ffc4206..497861e8ba 100644 --- a/teshsuite/simix/generic-simcalls/generic-simcalls.cpp +++ b/teshsuite/simix/generic-simcalls/generic-simcalls.cpp @@ -38,17 +38,17 @@ static int master(int argc, char* argv[]) XBT_INFO("kernel, returned"); // Synchronize on a successful Future: - simgrid::simix::kernelSync([] { + simgrid::simix::kernel_sync([] { return kernel_wait_until(10).then([](simgrid::kernel::Future future) { future.get(); - XBT_INFO("kernelSync with void"); + XBT_INFO("kernel_sync with void"); }); }); - XBT_INFO("kernelSync with void, returned"); + XBT_INFO("kernel_sync with void, returned"); // Synchronize on a failing Future: try { - simgrid::simix::kernelSync([] { + simgrid::simix::kernel_sync([] { return kernel_wait_until(20).then([](simgrid::kernel::Future future) { future.get(); throw example::exception("Exception throwed from kernel_defer"); @@ -60,31 +60,31 @@ static int master(int argc, char* argv[]) } // Synchronize on a successul Future and get the value: - int res = simgrid::simix::kernelSync([] { + int res = simgrid::simix::kernel_sync([] { return kernel_wait_until(30).then([](simgrid::kernel::Future future) { future.get(); - XBT_INFO("kernelSync with value"); + XBT_INFO("kernel_sync with value"); return 42; }); }); - XBT_INFO("kernelSync with value returned with %i", res); + XBT_INFO("kernel_sync with value returned with %i", res); // Synchronize on a successul Future and get the value: - simgrid::simix::Future future = simgrid::simix::kernelAsync([] { + simgrid::simix::Future future = simgrid::simix::kernel_async([] { return kernel_wait_until(50).then([](simgrid::kernel::Future future) { future.get(); - XBT_INFO("kernelAsync with value"); + XBT_INFO("kernel_async with value"); return 43; }); }); res = future.get(); - XBT_INFO("kernelAsync with value returned with %i", res); + XBT_INFO("kernel_async with value returned with %i", res); // Synchronize on a successul Future and get the value: - future = simgrid::simix::kernelAsync([] { + future = simgrid::simix::kernel_async([] { return kernel_wait_until(60).then([](simgrid::kernel::Future future) { future.get(); - XBT_INFO("kernelAsync with value"); + XBT_INFO("kernel_async with value"); return 43; }); }); @@ -92,7 +92,7 @@ static int master(int argc, char* argv[]) future.wait(); XBT_INFO("The future is %s", future.is_ready() ? "ready" : "not ready"); res = future.get(); - XBT_INFO("kernelAsync with value returned with %i", res); + XBT_INFO("kernel_async with value returned with %i", res); return 0; } diff --git a/teshsuite/simix/generic-simcalls/generic-simcalls.tesh b/teshsuite/simix/generic-simcalls/generic-simcalls.tesh index f168c68e89..0cbed1d9bc 100644 --- a/teshsuite/simix/generic-simcalls/generic-simcalls.tesh +++ b/teshsuite/simix/generic-simcalls/generic-simcalls.tesh @@ -2,14 +2,14 @@ $ ${bindir:=.}/generic-simcalls --cfg=contexts/stack-size:96 ${srcdir:=.}/exampl > [Tremblay:master:(1) 0.000000] [test/INFO] Start > [0.000000] [test/INFO] kernel > [Tremblay:master:(1) 0.000000] [test/INFO] kernel, returned -> [10.000000] [test/INFO] kernelSync with void -> [Tremblay:master:(1) 10.000000] [test/INFO] kernelSync with void, returned +> [10.000000] [test/INFO] kernel_sync with void +> [Tremblay:master:(1) 10.000000] [test/INFO] kernel_sync with void, returned > [Tremblay:master:(1) 20.000000] [test/INFO] Exception caught: Exception throwed from kernel_defer -> [30.000000] [test/INFO] kernelSync with value -> [Tremblay:master:(1) 30.000000] [test/INFO] kernelSync with value returned with 42 -> [50.000000] [test/INFO] kernelAsync with value -> [Tremblay:master:(1) 50.000000] [test/INFO] kernelAsync with value returned with 43 +> [30.000000] [test/INFO] kernel_sync with value +> [Tremblay:master:(1) 30.000000] [test/INFO] kernel_sync with value returned with 42 +> [50.000000] [test/INFO] kernel_async with value +> [Tremblay:master:(1) 50.000000] [test/INFO] kernel_async with value returned with 43 > [Tremblay:master:(1) 50.000000] [test/INFO] The future is not ready -> [60.000000] [test/INFO] kernelAsync with value +> [60.000000] [test/INFO] kernel_async with value > [Tremblay:master:(1) 60.000000] [test/INFO] The future is ready -> [Tremblay:master:(1) 60.000000] [test/INFO] kernelAsync with value returned with 43 \ No newline at end of file +> [Tremblay:master:(1) 60.000000] [test/INFO] kernel_async with value returned with 43 \ No newline at end of file