From: Frederic Suter Date: Tue, 19 Jun 2018 08:30:36 +0000 (+0200) Subject: more legacy MSG functions X-Git-Tag: v3.20~68 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4cedf6f3e1b53c5de2a19a293418a04c5d4d777f more legacy MSG functions --- diff --git a/ChangeLog b/ChangeLog index e74790207f..884042c215 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,11 @@ TRACE - Change --cfg=tracing/msg/vm to --cfg=tracing/vm as virtual machine behavior tracing is no longer limited to MSG +MSG + - The deprecation of MSG is ongoing. A lot of functions are now simple + wrappers on the C API of S4U. All these wrappers (and their S4U counterparts + can be found in src/msg/msg_legacy.cpp). + S4U: - Introduced new function simgrid::s4u::Host::get_actor_count. This function returns the number of actors running on a specific host. diff --git a/include/simgrid/engine.h b/include/simgrid/engine.h index 3908e454ae..e355a9d832 100644 --- a/include/simgrid/engine.h +++ b/include/simgrid/engine.h @@ -12,6 +12,7 @@ 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_run(); 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(); diff --git a/include/simgrid/mailbox.h b/include/simgrid/mailbox.h new file mode 100644 index 0000000000..6e91ff00c2 --- /dev/null +++ b/include/simgrid/mailbox.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_MAILBOX_H_ +#define INCLUDE_SIMGRID_MAILBOX_H_ + +#include +#include + +/* C interface */ +SG_BEGIN_DECL() + +void sg_mailbox_set_receiver(const char* alias); +int sg_mailbox_listen(const char* alias); + +SG_END_DECL() + +#endif /* INCLUDE_SIMGRID_MAILBOX_H_ */ diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index c22f43367e..b562b47a2a 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/src/bindings/java/jmsg_host.cpp b/src/bindings/java/jmsg_host.cpp index 166b570f59..7076f7a543 100644 --- a/src/bindings/java/jmsg_host.cpp +++ b/src/bindings/java/jmsg_host.cpp @@ -326,7 +326,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_all(JNIEnv * env, jclas JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_setAsyncMailbox(JNIEnv * env, jclass cls_arg, jobject jname) { const char *name = env->GetStringUTFChars((jstring) jname, 0); - MSG_mailbox_set_async(name); + sg_mailbox_set_receiver(name); env->ReleaseStringUTFChars((jstring) jname, name); } diff --git a/src/msg/msg_global.cpp b/src/msg/msg_global.cpp index cab13d920d..e6dd156a7d 100644 --- a/src/msg/msg_global.cpp +++ b/src/msg/msg_global.cpp @@ -55,23 +55,6 @@ void MSG_init_nocheck(int *argc, char **argv) { atexit(MSG_exit); } -/** \ingroup msg_simulation - * \brief Launch the MSG simulation - */ -msg_error_t MSG_main() -{ - /* Clean IO before the run */ - fflush(stdout); - fflush(stderr); - - if (MC_is_active()) { - MC_run(); - } else { - SIMIX_run(); - } - return MSG_OK; -} - /** \ingroup msg_simulation * \brief set a configuration variable * diff --git a/src/msg/msg_gos.cpp b/src/msg/msg_gos.cpp index dfc6ca9495..e9f5b1c319 100644 --- a/src/msg/msg_gos.cpp +++ b/src/msg/msg_gos.cpp @@ -849,19 +849,6 @@ msg_error_t MSG_task_send_with_timeout_bounded(msg_task_t task, const char *alia return MSG_task_send_with_timeout(task, alias, timeout); } -/** \ingroup msg_task_usage - * \brief Check if there is a communication going on in a mailbox. - * - * \param alias the name of the mailbox to be considered - * - * \return Returns 1 if there is a communication, 0 otherwise - */ -int MSG_task_listen(const char *alias) -{ - simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::by_name(alias); - return mbox->listen() ? 1 : 0; -} - /** \ingroup msg_task_usage * \brief Look if there is a communication on a mailbox and return the PID of the sender process. * diff --git a/src/msg/msg_legacy.cpp b/src/msg/msg_legacy.cpp index 43ac1771be..bb1148f6cf 100644 --- a/src/msg/msg_legacy.cpp +++ b/src/msg/msg_legacy.cpp @@ -17,6 +17,11 @@ void MSG_launch_application(const char* filename) { sg_engine_load_deployment(filename); } +msg_error_t MSG_main() +{ + sg_engine_run(); + return MSG_OK; +} void MSG_function_register(const char* name, xbt_main_func_t code) { sg_engine_register_function(name, code); @@ -29,6 +34,17 @@ double MSG_get_clock() { return sg_engine_get_clock(); } + +/* ************************** Mailboxes ************************ */ +void MSG_mailbox_set_async(const char* alias) +{ + sg_mailbox_set_receiver(alias); +} +int MSG_task_listen(const char* alias) +{ + return sg_mailbox_listen(alias); +} + /* ************************** Actors *************************** */ int MSG_process_get_PID(sg_actor_t actor) { diff --git a/src/msg/msg_mailbox.cpp b/src/msg/msg_mailbox.cpp deleted file mode 100644 index 12bb63293e..0000000000 --- a/src/msg/msg_mailbox.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* Mailboxes in MSG */ - -/* Copyright (c) 2008-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/s4u/Mailbox.hpp" -#include "src/msg/msg_private.hpp" - -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_mailbox, msg, "Logging specific to MSG (mailbox)"); - -/** \ingroup msg_mailbox_management - * \brief Set the mailbox to receive in asynchronous mode - * - * All messages sent to this mailbox will be transferred to the receiver without waiting for the receive call. - * The receive call will still be necessary to use the received data. - * If there is a need to receive some messages asynchronously, and some not, two different mailboxes should be used. - * - * \param alias The name of the mailbox - */ -void MSG_mailbox_set_async(const char *alias){ - simgrid::s4u::Mailbox::by_name(alias)->set_receiver(simgrid::s4u::Actor::self()); - XBT_VERB("%s mailbox set to receive eagerly for myself\n",alias); -} diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index ac01c07206..330b7ea38f 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -249,6 +249,10 @@ std::vector Engine::get_filtered_actors(std::function void Engine::run() { + /* Clean IO before the run */ + fflush(stdout); + fflush(stderr); + if (MC_is_active()) { MC_run(); } else { @@ -346,7 +350,10 @@ void sg_engine_load_deployment(const char* file) { simgrid::s4u::Engine::get_instance()->load_deployment(file); } - +void sg_engine_run() +{ + simgrid::s4u::Engine::get_instance()->run(); +} void sg_engine_register_function(const char* name, int (*code)(int, char**)) { simgrid::s4u::Engine::get_instance()->register_function(name, code); diff --git a/src/s4u/s4u_Mailbox.cpp b/src/s4u/s4u_Mailbox.cpp index a294219761..7c3841ed02 100644 --- a/src/s4u/s4u_Mailbox.cpp +++ b/src/s4u/s4u_Mailbox.cpp @@ -145,3 +145,28 @@ void* Mailbox::get(double timeout) } } // namespace s4u } // namespace simgrid + +/* **************************** Public C interface *************************** */ +/** \brief Set the mailbox to receive in asynchronous mode + * + * All messages sent to this mailbox will be transferred to the receiver without waiting for the receive call. + * The receive call will still be necessary to use the received data. + * If there is a need to receive some messages asynchronously, and some not, two different mailboxes should be used. + * + * \param alias The name of the mailbox + */ +void sg_mailbox_set_receiver(const char* alias) +{ + simgrid::s4u::Mailbox::by_name(alias)->set_receiver(simgrid::s4u::Actor::self()); + XBT_VERB("%s mailbox set to receive eagerly for myself\n", alias); +} + +/** \brief Check if there is a communication going on in a mailbox. + * + * \param alias the name of the mailbox to be considered + * \return Returns 1 if there is a communication, 0 otherwise + */ +int sg_mailbox_listen(const char* alias) +{ + return simgrid::s4u::Mailbox::by_name(alias)->listen() ? 1 : 0; +} diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 0d0ed04d19..be8804daef 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -444,7 +444,6 @@ set(MSG_SRC src/msg/msg_global.cpp src/msg/msg_gos.cpp src/msg/msg_legacy.cpp - src/msg/msg_mailbox.cpp src/msg/msg_process.cpp src/msg/msg_synchro.cpp src/msg/msg_task.cpp @@ -670,6 +669,7 @@ set(headers_to_install include/simgrid/plugins/load_balancer.h include/simgrid/smpi/replay.hpp include/simgrid/instr.h + include/simgrid/mailbox.h include/simgrid/msg.h include/simgrid/simdag.h include/simgrid/modelchecker.h