From: Gabriel Corona Date: Thu, 21 Jul 2016 10:06:16 +0000 (+0200) Subject: [mc] this_actor, wait_for and wait_until X-Git-Tag: v3_14~737^2~2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/cda7600c05eaa0eb26fc870b911703f806bdaea2 [mc] this_actor, wait_for and wait_until For consistency avec ConditionVariable and the C++ standard library. --- diff --git a/examples/s4u/mutex/s4u_mutex.cpp b/examples/s4u/mutex/s4u_mutex.cpp index c9073e4398..99102903b3 100644 --- a/examples/s4u/mutex/s4u_mutex.cpp +++ b/examples/s4u/mutex/s4u_mutex.cpp @@ -55,7 +55,7 @@ static void master() simgrid::s4u::Actor::createActor("worker", simgrid::s4u::Host::by_name("Tremblay"), worker, mutex, std::ref(result)); } - simgrid::s4u::this_actor::sleep(10); + simgrid::s4u::this_actor::sleep_for(10); XBT_INFO("Results is -> %d", result); } diff --git a/include/simgrid/s4u/actor.hpp b/include/simgrid/s4u/actor.hpp index 5039f84983..f5de6051c9 100644 --- a/include/simgrid/s4u/actor.hpp +++ b/include/simgrid/s4u/actor.hpp @@ -258,13 +258,26 @@ using ActorPtr = Actor::Ptr; namespace this_actor { /** Block the actor sleeping for that amount of seconds (may throws hostFailure) */ - XBT_PUBLIC(void) sleep(double duration); + XBT_PUBLIC(void) sleep_for(double duration); + XBT_PUBLIC(void) sleep_until(double timeout); template - inline void sleep(std::chrono::duration duration) + inline void sleep_for(std::chrono::duration duration) { auto seconds = std::chrono::duration_cast(duration); - sleep(seconds.count()); + this_actor::sleep_for(seconds.count()); + } + template + inline void sleep_until(const SimulationTimePoint& timeout_time) + { + auto timeout_native = std::chrono::time_point_cast(timeout_time); + this_actor::sleep_until(timeout_native.time_since_epoch().count()); + } + + XBT_ATTRIB_DEPRECATED("Use sleep_for()") + inline void sleep(double duration) + { + return sleep_for(duration); } /** Block the actor, computing the given amount of flops */ diff --git a/src/mc/Session.cpp b/src/mc/Session.cpp index ff6cef6481..260edd47eb 100644 --- a/src/mc/Session.cpp +++ b/src/mc/Session.cpp @@ -165,10 +165,10 @@ Session* Session::spawnv(const char *path, char *const argv[]) } // static -Session* Session::spawnvp(const char *path, char *const argv[]) +Session* Session::spawnvp(const char *file, char *const argv[]) { return Session::fork([&] { - execvp(path, argv); + execvp(file, argv); }); } diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp index 016e38e081..d8ad4a27d6 100644 --- a/src/s4u/s4u_actor.cpp +++ b/src/s4u/s4u_actor.cpp @@ -110,8 +110,17 @@ void Actor::killAll() { namespace this_actor { -void sleep(double duration) { - simcall_process_sleep(duration); +void sleep_for(double duration) +{ + if (duration > 0) + simcall_process_sleep(duration); +} + +XBT_PUBLIC(void) sleep_until(double timeout) +{ + double now = SIMIX_get_clock(); + if (timeout > now) + simcall_process_sleep(timeout - now); } e_smx_state_t execute(double flops) {