From e34aedcc066725448eee18de1aea881fd6697ba1 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Sun, 6 May 2018 16:20:31 +0200 Subject: [PATCH] more legacy MSG functions --- include/simgrid/actor.h | 5 ++- include/simgrid/engine.h | 20 +++++++++++ include/simgrid/msg.h | 6 ++-- src/msg/msg_deployment.cpp | 59 -------------------------------- src/msg/msg_environment.cpp | 33 ------------------ src/msg/msg_global.cpp | 23 +++---------- src/msg/msg_legacy.cpp | 31 ++++++++++++++++- src/msg/msg_process.cpp | 6 ---- src/s4u/s4u_Actor.cpp | 11 ++++++ src/s4u/s4u_Engine.cpp | 24 +++++++++++++ tools/cmake/DefinePackages.cmake | 3 +- 11 files changed, 96 insertions(+), 125 deletions(-) create mode 100644 include/simgrid/engine.h delete mode 100644 src/msg/msg_deployment.cpp delete mode 100644 src/msg/msg_environment.cpp diff --git a/include/simgrid/actor.h b/include/simgrid/actor.h index ebbc070ca5..0e72156dd0 100644 --- a/include/simgrid/actor.h +++ b/include/simgrid/actor.h @@ -1,5 +1,3 @@ -/* Public interface to the Link datatype */ - /* Copyright (c) 2018. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -22,7 +20,6 @@ SG_BEGIN_DECL() You should not access directly to the fields of the pointed structure, but always use the provided API to interact with actors. */ - XBT_PUBLIC int sg_actor_get_PID(sg_actor_t actor); XBT_PUBLIC int sg_actor_get_PPID(sg_actor_t actor); XBT_PUBLIC sg_actor_t sg_actor_by_PID(aid_t pid); @@ -38,7 +35,9 @@ XBT_PUBLIC void sg_actor_daemonize(sg_actor_t actor); XBT_PUBLIC void sg_actor_migrate(sg_actor_t process, sg_host_t host); XBT_PUBLIC void sg_actor_join(sg_actor_t actor, double timeout); XBT_PUBLIC void sg_actor_kill(sg_actor_t actor); +XBT_PUBLIC void sg_actor_kill_all(); XBT_PUBLIC void sg_actor_set_kill_time(sg_actor_t actor, double kill_time); +XBT_PUBLIC void sg_actor_yield(); SG_END_DECL() #endif /* INCLUDE_SIMGRID_ACTOR_H_ */ diff --git a/include/simgrid/engine.h b/include/simgrid/engine.h new file mode 100644 index 0000000000..3908e454ae --- /dev/null +++ b/include/simgrid/engine.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2018. 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_ENGINE_H_ +#define INCLUDE_SIMGRID_ENGINE_H_ + +#include + +/* C interface */ +SG_BEGIN_DECL() +XBT_PUBLIC void sg_engine_load_platform(const char* filename); +XBT_PUBLIC void sg_engine_load_deployment(const char* filename); +XBT_PUBLIC void sg_engine_register_function(const char* name, int (*code)(int, char**)); +XBT_PUBLIC void sg_engine_register_default(int (*code)(int, char**)); +XBT_PUBLIC double sg_engine_get_clock(); +SG_END_DECL() + +#endif /* INCLUDE_SIMGRID_ENGINE_H_ */ diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index 1ea45bfdc7..173a1de00e 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -7,6 +7,7 @@ #define SIMGRID_MSG_H #include +#include #include #include #include @@ -143,7 +144,9 @@ XBT_PUBLIC void MSG_process_daemonize(msg_process_t process); XBT_PUBLIC void MSG_process_migrate(msg_process_t process, msg_host_t host); XBT_PUBLIC void MSG_process_join(msg_process_t process, double timeout); XBT_PUBLIC void MSG_process_kill(msg_process_t process); +XBT_PUBLIC void MSG_process_killall(); XBT_PUBLIC void MSG_process_set_kill_time(msg_process_t process, double kill_time); +XBT_PUBLIC void MSG_process_yield(); /* ******************************** File ************************************ */ typedef sg_file_t msg_file_t; @@ -241,9 +244,6 @@ XBT_PUBLIC msg_process_t MSG_process_create_with_environment(const char* name, x XBT_PUBLIC msg_process_t MSG_process_attach(const char* name, void* data, msg_host_t host, xbt_dict_t properties); XBT_PUBLIC void MSG_process_detach(); -XBT_PUBLIC int MSG_process_killall(); -XBT_PUBLIC void MSG_process_yield(); - XBT_PUBLIC void MSG_process_set_data_cleanup(void_f_pvoid_t data_cleanup); XBT_PUBLIC int MSG_process_self_PID(); XBT_PUBLIC int MSG_process_self_PPID(); diff --git a/src/msg/msg_deployment.cpp b/src/msg/msg_deployment.cpp deleted file mode 100644 index 8382a6284e..0000000000 --- a/src/msg/msg_deployment.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright (c) 2004-2018. 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. */ - -#include "src/msg/msg_private.hpp" - -/** \ingroup msg_simulation - * \brief An application deployer. - * - * Creates the process described in \a file. - * \param file a filename of a xml description of the application. This file follows this DTD : - * - * \include simgrid.dtd - * - * Here is a small example of such a platform - * - * \include msg/masterslave/deployment_masterslave.xml - * - * Have a look in the directory examples/msg/ to have a bigger example. - */ -void MSG_launch_application(const char *file) -{ - xbt_assert(msg_global, "MSG_init has to be called before MSG_launch_application."); - SIMIX_launch_application(file); -} - -/** \ingroup msg_simulation - * \brief Registers the main function of a process in a global table. - * - * Registers a code function in a global table. - * This table is then used by #MSG_launch_application. - * \param name the reference name of the function. - * \param code the function (must have the same prototype than the main function of any C program: int ..(int argc, char *argv[])) - */ -void MSG_function_register(const char *name, xbt_main_func_t code) -{ - SIMIX_function_register(name, code); -} - -/** \ingroup msg_simulation - * \brief Registers a function as the default main function of processes. - * - * Registers a code function as being the default value. This function will get used by MSG_launch_application() when there is no registered function of the requested name in. - * \param code the function (must have the same prototype than the main function of any C program: int ..(int argc, char *argv[])) - */ -void MSG_function_register_default(xbt_main_func_t code) -{ - SIMIX_function_register_default(code); -} - -/** - * \brief register functions bypassing the parser - */ - -void MSG_set_function(const char *host_id, const char *function_name, xbt_dynar_t arguments) -{ - SIMIX_process_set_function(host_id, function_name, arguments, -1, -1); -} diff --git a/src/msg/msg_environment.cpp b/src/msg/msg_environment.cpp deleted file mode 100644 index 5bdf7aecf3..0000000000 --- a/src/msg/msg_environment.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright (c) 2004-2018. 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. */ - -#include "simgrid/msg.h" - -#if SIMGRID_HAVE_LUA -#include -#include -#include -#endif - -/********************************* MSG **************************************/ - -/** \ingroup msg_simulation - * \brief A platform constructor. - * - * Creates a new platform, including hosts, links and the routing_table. - * \param file a filename of a xml description of a platform. This file follows this DTD : - * - * \include simgrid.dtd - * - * Here is a small example of such a platform - * - * \include small_platform.xml - * - * Have a look in the directory examples/msg/ to have a big example. - */ -void MSG_create_environment(const char *file) -{ - SIMIX_create_environment(file); -} diff --git a/src/msg/msg_global.cpp b/src/msg/msg_global.cpp index cf4cda0d36..c90d181b16 100644 --- a/src/msg/msg_global.cpp +++ b/src/msg/msg_global.cpp @@ -3,7 +3,6 @@ /* 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/s4u/Actor.hpp" #include "simgrid/s4u/Engine.hpp" #include "simgrid/s4u/Host.hpp" @@ -86,16 +85,6 @@ void MSG_config(const char *key, const char *value){ simgrid::config::set_as_string(key, value); } -/** \ingroup msg_simulation - * \brief Kill all running process - - */ -int MSG_process_killall() -{ - simgrid::s4u::Actor::kill_all(); - return 0; -} - static void MSG_exit() { if (msg_global==nullptr) return; @@ -104,15 +93,13 @@ static void MSG_exit() { msg_global = nullptr; } -/** \ingroup msg_simulation - * \brief A clock (in second). - */ -double MSG_get_clock() +unsigned long int MSG_get_sent_msg() { - return SIMIX_get_clock(); + return msg_global->sent_msg; } -unsigned long int MSG_get_sent_msg() +/** \brief register functions bypassing the parser */ +void MSG_set_function(const char* host_id, const char* function_name, xbt_dynar_t arguments) { - return msg_global->sent_msg; + SIMIX_process_set_function(host_id, function_name, arguments, -1, -1); } diff --git a/src/msg/msg_legacy.cpp b/src/msg/msg_legacy.cpp index 304dab0d1f..c3a28cb86a 100644 --- a/src/msg/msg_legacy.cpp +++ b/src/msg/msg_legacy.cpp @@ -7,6 +7,28 @@ #define MSG_CALL(type, oldname, args) +/* ************************** Engine *************************** */ +void MSG_create_environment(const char* filename) +{ + sg_engine_load_platform(filename); +} + +void MSG_launch_application(const char* filename) +{ + sg_engine_load_deployment(filename); +} +void MSG_function_register(const char* name, xbt_main_func_t code) +{ + sg_engine_register_function(name, code); +} +void MSG_function_register_default(xbt_main_func_t code) +{ + sg_engine_register_default(code); +} +double MSG_get_clock() +{ + return sg_engine_get_clock(); +} /* ************************** Actors *************************** */ int MSG_process_get_PID(sg_actor_t actor) { @@ -68,11 +90,18 @@ void MSG_process_kill(sg_actor_t actor) { sg_actor_kill(actor); } - +void MSG_process_kill_all() +{ + sg_actor_kill_all(); +} void MSG_process_set_kill_time(sg_actor_t actor, double kill_time) { sg_actor_set_kill_time(actor, kill_time); } +void MSG_process_yield() +{ + sg_actor_yield(); +} /* ************************** NetZones *************************** */ sg_netzone_t MSG_zone_get_root() diff --git a/src/msg/msg_process.cpp b/src/msg/msg_process.cpp index bbadeabbf0..3a82a9add1 100644 --- a/src/msg/msg_process.cpp +++ b/src/msg/msg_process.cpp @@ -196,12 +196,6 @@ void MSG_process_detach() SIMIX_process_detach(); } -/** Yield the current actor; let the other actors execute first */ -void MSG_process_yield() -{ - simgrid::simix::kernelImmediate([] { /* do nothing*/ }); -} - /** \ingroup m_process_management * \brief Returns the user data of a process. * diff --git a/src/s4u/s4u_Actor.cpp b/src/s4u/s4u_Actor.cpp index b342ac47f3..e67eaa10f3 100644 --- a/src/s4u/s4u_Actor.cpp +++ b/src/s4u/s4u_Actor.cpp @@ -570,6 +570,11 @@ void sg_actor_kill(sg_actor_t actor) actor->kill(); } +void sg_actor_kill_all() +{ + simgrid::s4u::Actor::kill_all(); +} + /** \ingroup m_actor_management * \brief Set the kill time of an actor. * @@ -580,3 +585,9 @@ void sg_actor_set_kill_time(sg_actor_t actor, double kill_time) { actor->set_kill_time(kill_time); } + +/** Yield the current actor; let the other actors execute first */ +void sg_actor_yield() +{ + simgrid::s4u::this_actor::yield(); +} diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index 1263f114b0..9bcbae96a2 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -260,3 +260,27 @@ void Engine::set_config(std::string str) } } // namespace s4u } // namespace simgrid + +/* **************************** Public C interface *************************** */ +void sg_engine_load_platform(const char* file) +{ + simgrid::s4u::Engine::get_instance()->load_platform(file); +} + +void sg_engine_load_deployment(const char* file) +{ + simgrid::s4u::Engine::get_instance()->load_deployment(file); +} + +void sg_engine_register_function(const char* name, int (*code)(int, char**)) +{ + simgrid::s4u::Engine::get_instance()->register_function(name, code); +} +void sg_engine_register_default(int (*code)(int, char**)) +{ + simgrid::s4u::Engine::get_instance()->register_default(code); +} +double sg_engine_get_clock() +{ + return simgrid::s4u::Engine::get_clock(); +} diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index ba4852daaa..981ba71490 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -442,8 +442,6 @@ set(SIMGRID_SRC set(MSG_SRC src/msg/instr_msg_process.cpp src/msg/instr_msg_task.cpp - src/msg/msg_deployment.cpp - src/msg/msg_environment.cpp src/msg/msg_global.cpp src/msg/msg_gos.cpp src/msg/msg_legacy.cpp @@ -662,6 +660,7 @@ set(MC_SIMGRID_MC_SRC src/mc/checker/simgrid_mc.cpp) set(headers_to_install include/simgrid/actor.h + include/simgrid/engine.h include/simgrid/chrono.hpp include/simgrid/plugins/dvfs.h include/simgrid/plugins/energy.h -- 2.20.1