From: Frederic Suter Date: Sat, 7 Mar 2020 13:26:16 +0000 (+0100) Subject: more sg_exec functions X-Git-Tag: v3.26~785 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3043ae53cf341baaa0dfaa6658be66f83c91a4c2 more sg_exec functions --- diff --git a/include/simgrid/exec.h b/include/simgrid/exec.h index b74cfad49a..4dee58abb3 100644 --- a/include/simgrid/exec.h +++ b/include/simgrid/exec.h @@ -13,6 +13,8 @@ SG_BEGIN_DECL XBT_PUBLIC void sg_exec_set_bound(sg_exec_t exec, double bound); +XBT_PUBLIC const char* sg_exec_get_name(sg_exec_t exec); +XBT_PUBLIC void sg_exec_set_name(sg_exec_t exec, const char* name); XBT_PUBLIC void sg_exec_set_host(sg_exec_t exec, sg_host_t new_host); XBT_PUBLIC double sg_exec_get_remaining(const_sg_exec_t exec); XBT_PUBLIC double sg_exec_get_remaining_ratio(const_sg_exec_t exec); @@ -22,6 +24,8 @@ XBT_PUBLIC void sg_exec_cancel(sg_exec_t exec); XBT_PUBLIC int sg_exec_test(sg_exec_t exec); XBT_PUBLIC sg_error_t sg_exec_wait(sg_exec_t exec); XBT_PUBLIC sg_error_t sg_exec_wait_for(sg_exec_t exec, double timeout); +XBT_PUBLIC int sg_exec_wait_any_for(sg_exec_t* execs, size_t count, double timeout); +XBT_PUBLIC int sg_exec_wait_any(sg_exec_t* execs, size_t count); SG_END_DECL diff --git a/src/s4u/s4u_Exec.cpp b/src/s4u/s4u_Exec.cpp index ba688e407c..86926f85aa 100644 --- a/src/s4u/s4u_Exec.cpp +++ b/src/s4u/s4u_Exec.cpp @@ -217,6 +217,16 @@ void sg_exec_set_bound(sg_exec_t exec, double bound) exec->set_bound(bound); } +const char* sg_exec_get_name(sg_exec_t exec) +{ + return exec->get_cname(); +} + +void sg_exec_set_name(sg_exec_t exec, const char* name) +{ + exec->set_name(name); +} + void sg_exec_set_host(sg_exec_t exec, sg_host_t new_host) { exec->set_host(new_host); @@ -283,3 +293,24 @@ sg_error_t sg_exec_wait_for(sg_exec_t exec, double timeout) exec->unref(); return status; } + +int sg_exec_wait_any(sg_exec_t* execs, size_t count) +{ + return sg_exec_wait_any_for(execs, count, -1); +} + +int sg_exec_wait_any_for(sg_exec_t* execs, size_t count, double timeout) +{ + std::vector s4u_execs; + for (unsigned int i = 0; i < count; i++) { + s4u_execs.emplace_back(execs[i]); + } + int pos = simgrid::s4u::Exec::wait_any_for(&s4u_execs, timeout); + if (pos != -1) + s4u_execs[pos]->unref(); + else + for (const auto& e : s4u_execs) + e->unref(); + + return pos; +}