X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/84402e8e2ee2a2d0bef25fdceb0a263ed8b471f6..3ba1bd7a72e4572ac25f6a6271be8cb29ed538de:/src/msg/msg_legacy.cpp diff --git a/src/msg/msg_legacy.cpp b/src/msg/msg_legacy.cpp index da208dd5a5..c76bad3dad 100644 --- a/src/msg/msg_legacy.cpp +++ b/src/msg/msg_legacy.cpp @@ -4,7 +4,9 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "simgrid/Exception.hpp" +#include "simgrid/s4u/Engine.hpp" #include "src/msg/msg_private.hpp" +#include "xbt/functional.hpp" #define MSG_CALL(type, oldname, args) @@ -23,13 +25,17 @@ msg_error_t MSG_main() simgrid_run(); return MSG_OK; } -void MSG_function_register(const char* name, xbt_main_func_t code) +void MSG_function_register(const char* name, int (*code)(int, char**)) { - simgrid_register_function(name, code); + simgrid::kernel::actor::ActorCodeFactory code_factory = [code](std::vector args) { + return simgrid::xbt::wrap_main(code, std::move(args)); + }; + simgrid::s4u::Engine::get_instance()->register_function(name, code_factory); } -void MSG_function_register_default(xbt_main_func_t code) +void MSG_function_register_default(int (*code)(int, char**)) { - simgrid_register_default(code); + simgrid::s4u::Engine::get_instance()->register_default( + [code](std::vector args) { return simgrid::xbt::wrap_main(code, std::move(args)); }); } double MSG_get_clock() { @@ -47,6 +53,13 @@ int MSG_task_listen(const char* alias) } /* ************************** Actors *************************** */ +void MSG_process_on_exit(int_f_int_pvoid_t fun, void* data) +{ + /* We can't use the sg_actor_on_exit, as the return type of the callback changed: the int in MSG is ignored and was + * removed in sg */ + simgrid::s4u::this_actor::on_exit([fun, data](bool failed) { fun(failed ? 1 /*FAILURE*/ : 0 /*SUCCESS*/, data); }); +} + int MSG_process_get_PID(const_sg_actor_t actor) { return sg_actor_get_PID(actor); @@ -207,9 +220,9 @@ void MSG_process_unref(const_sg_actor_t process) sg_actor_unref(process); } /** @brief Return the current number MSG processes. */ -int MSG_process_get_number() +int MSG_process_get_number() // XBT_ATTRIB_DEPRECATED_v330 { - return simgrid_get_actor_count(); + return sg_actor_count(); } /* ************************** NetZones *************************** */ sg_netzone_t MSG_zone_get_root() @@ -288,9 +301,17 @@ sg_size_t MSG_storage_write(sg_storage_t storage, sg_size_t size) } /* ************************** hosts *************************** */ -xbt_dynar_t MSG_hosts_as_dynar() +xbt_dynar_t MSG_hosts_as_dynar() // XBT_ATTRIB_DEPRECATED_v330 { - return sg_hosts_as_dynar(); + size_t host_count = sg_host_count(); + sg_host_t* list = sg_host_list(); + + xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t), nullptr); + for (size_t i = 0; i < host_count; i++) + xbt_dynar_push_as(res, sg_host_t, list[i]); + xbt_free(list); + + return res; } size_t MSG_get_host_number() { @@ -316,7 +337,7 @@ void MSG_host_set_data(sg_host_t host, void* data) { return sg_host_data_set(host, data); } -xbt_dict_t MSG_host_get_mounted_storage_list(sg_host_t host) +xbt_dict_t MSG_host_get_mounted_storage_list(sg_host_t host) // XBT_ATTRIB_DEPRECATED_v330 { return sg_host_get_mounted_storage_list(host); }