From: Frederic Suter Date: Wed, 19 Feb 2020 14:35:41 +0000 (+0100) Subject: extend C API for asynchronous executions X-Git-Tag: v3.26~940 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/841d7ae6385610f340ae3c0be8273bdd9ec80cd5 extend C API for asynchronous executions --- diff --git a/include/simgrid/actor.h b/include/simgrid/actor.h index 63b544f24a..b5de5fdeb5 100644 --- a/include/simgrid/actor.h +++ b/include/simgrid/actor.h @@ -70,6 +70,8 @@ XBT_PUBLIC void sg_actor_unref(const_sg_actor_t actor); XBT_PUBLIC void* sg_actor_data(const_sg_actor_t actor); XBT_PUBLIC void sg_actor_data_set(sg_actor_t actor, void* userdata); +XBT_PUBLIC sg_exec_t sg_actor_exec_init(double computation_amount); +XBT_PUBLIC sg_exec_t sg_actor_exec_async(double computation_amount); SG_END_DECL #endif /* INCLUDE_SIMGRID_ACTOR_H_ */ diff --git a/include/simgrid/exec.h b/include/simgrid/exec.h new file mode 100644 index 0000000000..17e7ae9596 --- /dev/null +++ b/include/simgrid/exec.h @@ -0,0 +1,24 @@ +/* Copyright (c) 2018-2020. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef INCLUDE_SIMGRID_EXEC_H_ +#define INCLUDE_SIMGRID_EXEC_H_ + +#include +#include + +/* C interface */ +SG_BEGIN_DECL + +XBT_PUBLIC void sg_exec_set_bound(sg_exec_t exec, double bound); +XBT_PUBLIC double sg_exec_get_remaining(sg_exec_t exec); + +XBT_PUBLIC void sg_exec_start(sg_exec_t exec); +XBT_PUBLIC void sg_exec_wait(sg_exec_t exec); +XBT_PUBLIC void sg_exec_wait_for(sg_exec_t exec, double timeout); + +SG_END_DECL + +#endif /* INCLUDE_SIMGRID_COMM_H_ */ diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index 6ab12acdc5..e230a33afa 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -773,3 +773,17 @@ void sg_actor_on_exit(int_f_int_pvoid_t fun, void* data) { simgrid::s4u::this_actor::on_exit([fun, data](bool failed) { fun(failed ? 1 /*FAILURE*/ : 0 /*SUCCESS*/, data); }); } + +sg_exec_t sg_actor_exec_init(double computation_amount) +{ + simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(computation_amount); + exec->add_ref(); + return exec.get(); +} + +sg_exec_t sg_actor_exec_async(double computation_amount) +{ + simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_async(computation_amount); + exec->add_ref(); + return exec.get(); +} diff --git a/src/s4u/s4u_Exec.cpp b/src/s4u/s4u_Exec.cpp index ca551bfcc7..6d629ed30e 100644 --- a/src/s4u/s4u_Exec.cpp +++ b/src/s4u/s4u_Exec.cpp @@ -3,6 +3,7 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include "simgrid/exec.h" #include "simgrid/s4u/Actor.hpp" #include "simgrid/s4u/Exec.hpp" #include "src/kernel/activity/ExecImpl.hpp" @@ -209,3 +210,30 @@ double Exec::get_remaining_ratio() const } // namespace s4u } // namespace simgrid +/* **************************** Public C interface *************************** */ +void sg_exec_set_bound(sg_exec_t exec, double bound) +{ + exec->set_bound(bound); +} + +double sg_exec_get_remaining(sg_exec_t exec) +{ + return exec->get_remaining(); +} + +void sg_exec_start(sg_exec_t exec) +{ + exec->start(); +} + +void sg_exec_wait(sg_exec_t exec) +{ + exec->wait_for(-1); + exec->unref(); +} + +void sg_exec_wait_for(sg_exec_t exec, double timeout) +{ + exec->wait_for(timeout); + exec->unref(); +} diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 7b922bca9e..2b827e949e 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -680,6 +680,7 @@ set(headers_to_install include/simgrid/barrier.h include/simgrid/comm.h include/simgrid/engine.h + include/simgrid/exec.h include/simgrid/Exception.hpp include/simgrid/chrono.hpp include/simgrid/plugins/dvfs.h