Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
tesh conversion
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 27 Mar 2017 08:16:07 +0000 (10:16 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 27 Mar 2017 08:16:07 +0000 (10:16 +0200)
add Mailbox::listen() and this_actor::isend() in the process

include/simgrid/s4u/Actor.hpp
include/simgrid/s4u/Mailbox.hpp
src/msg/msg_gos.cpp
src/s4u/s4u_actor.cpp
src/s4u/s4u_mailbox.cpp
teshsuite/msg/CMakeLists.txt
teshsuite/msg/listen_async/listen_async.c [deleted file]
teshsuite/msg/listen_async/listen_async.tesh [deleted file]
teshsuite/s4u/CMakeLists.txt
teshsuite/s4u/listen_async/listen_async.cpp [new file with mode: 0644]
teshsuite/s4u/listen_async/listen_async.tesh [new file with mode: 0644]

index 713127f..2196ead 100644 (file)
@@ -306,6 +306,8 @@ namespace this_actor {
   */
   XBT_PUBLIC(void) send(MailboxPtr chan, void* payload, double simulatedSize);
 
+  XBT_PUBLIC(void) isend(MailboxPtr chan, void* payload, double simulatedSize);
+
   /** @brief Returns the PID of the current actor. */
   XBT_PUBLIC(int) pid();
 
index 9d52198..bd0a479 100644 (file)
@@ -132,6 +132,9 @@ public:
   /** Returns whether the mailbox contains queued communications */
   bool empty();
 
+  /** Check if there is a communication going on in a mailbox. */
+  bool listen();
+
   /** Gets the first element in the queue (without dequeuing it), or nullptr if none is there */
   smx_activity_t front();
 
index 8fc4a95..7d50008 100644 (file)
@@ -848,8 +848,7 @@ msg_error_t MSG_task_send_with_timeout_bounded(msg_task_t task, const char *alia
 int MSG_task_listen(const char *alias)
 {
   simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(alias);
-  return !mbox->empty() ||
-    (mbox->getImpl()->permanent_receiver && !mbox->getImpl()->done_comm_queue.empty());
+  return mbox->listen() ? 1 : 0;
 }
 
 /** \ingroup msg_task_usage
index f16cabf..c1c7ed2 100644 (file)
@@ -190,6 +190,11 @@ void send(MailboxPtr chan, void* payload, double simulatedSize)
   c.wait();
 }
 
+void isend(MailboxPtr chan, void* payload, double simulatedSize)
+{
+  Comm::send_async(chan, payload, simulatedSize);
+}
+
 int pid()
 {
   return SIMIX_process_self()->pid;
index b2cbb4d..2e6ad2c 100644 (file)
@@ -41,6 +41,11 @@ bool Mailbox::empty()
   return pimpl_->comm_queue.empty();
 }
 
+bool Mailbox::listen()
+{
+  return !this->empty() || (pimpl_->permanent_receiver && !pimpl_->done_comm_queue.empty());
+}
+
 smx_activity_t Mailbox::front()
 {
   return pimpl_->comm_queue.empty() ? nullptr : pimpl_->comm_queue.front();
index 28cdd2c..d7e61e4 100644 (file)
@@ -1,5 +1,5 @@
 # C examples
-foreach(x get_sender host_on_off host_on_off_recv host_on_off_processes host_on_off_wait listen_async
+foreach(x get_sender host_on_off host_on_off_recv host_on_off_processes host_on_off_wait
           storage_client_server trace_integration)
   add_executable       (${x}  ${x}/${x}.c)
   target_link_libraries(${x}  simgrid)
@@ -34,7 +34,7 @@ set(xml_files     ${xml_files}     ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration
                                    ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration/test-hbp1-c1s1-c3s2.xml
                                    ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration/test-hbp2.5-hbp1.5.xml    PARENT_SCOPE)
 
-foreach(x get_sender host_on_off host_on_off_processes host_on_off_recv host_on_off_wait listen_async
+foreach(x get_sender host_on_off host_on_off_processes host_on_off_recv host_on_off_wait
           storage_client_server task_destroy_cancel trace_integration)
   ADD_TESH_FACTORIES(tesh-msg-${x} "thread;boost;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x} --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x}/${x}.tesh)
 endforeach()
diff --git a/teshsuite/msg/listen_async/listen_async.c b/teshsuite/msg/listen_async/listen_async.c
deleted file mode 100644 (file)
index 10c97d7..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/* Bug report: https://github.com/simgrid/simgrid/issues/40
- * 
- * Task.listen used to be on async mailboxes as it always returned false.
- * This occures in Java and C, but is only tested here in C.
- */
-
-#include "simgrid/msg.h"
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
-
-static int server(int argc, char *argv[])
-{
-   msg_task_t task =  MSG_task_create("a", 0, 0, (char*)"Some data");
-   MSG_task_isend(task, "mailbox");
-
-   xbt_assert(MSG_task_listen("mailbox")); // True (1)
-   XBT_INFO("Task listen works on regular mailboxes");
-   task = NULL;
-   MSG_task_receive(&task, "mailbox");
-   xbt_assert(!strcmp("Some data", MSG_task_get_data(task)), "Data received: %s", (char*)MSG_task_get_data(task));
-   MSG_task_destroy(task);
-   XBT_INFO("Data successfully received from regular mailbox");
-
-   MSG_mailbox_set_async("mailbox2");
-   task = MSG_task_create("b", 0, 0, (char*)"More data");
-   MSG_task_isend(task, "mailbox2");
-
-   xbt_assert(MSG_task_listen("mailbox2")); // used to break.
-   XBT_INFO("Task listen works on asynchronous mailboxes");
-   task = NULL;
-   MSG_task_receive(&task, "mailbox2");
-   xbt_assert(!strcmp("More data", MSG_task_get_data(task)));
-   MSG_task_destroy(task);
-   XBT_INFO("Data successfully received from asynchronous mailbox");
-
-   return 0;
-}
-
-int main(int argc, char *argv[])
-{
-   MSG_init(&argc, argv);
-   xbt_assert(argc==2);
-   MSG_create_environment(argv[1]);
-   MSG_process_create("test", server, NULL, MSG_host_by_name("Tremblay"));
-   MSG_main();
-
-   return 0;
-}
diff --git a/teshsuite/msg/listen_async/listen_async.tesh b/teshsuite/msg/listen_async/listen_async.tesh
deleted file mode 100644 (file)
index c92957e..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-$ ./listen_async ${srcdir:=.}/../../../examples/platforms/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [  0.000000] (1:test@Tremblay) Task listen works on regular mailboxes
-> [  0.000195] (1:test@Tremblay) Data successfully received from regular mailbox
-> [  0.000195] (1:test@Tremblay) Task listen works on asynchronous mailboxes
-> [  0.000195] (1:test@Tremblay) Data successfully received from asynchronous mailbox
-> [  0.000195] (0:maestro@) Variable 3 still in system when freing it: this may be a bug
index 12c25fe..0630150 100644 (file)
@@ -1,4 +1,4 @@
-foreach(x actor concurrent_rw pid)
+foreach(x actor concurrent_rw listen_async pid)
   add_executable       (${x}  ${x}/${x}.cpp)
   target_link_libraries(${x}  simgrid)
   set_target_properties(${x}  PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x})
@@ -11,6 +11,6 @@ set(teshsuite_src ${teshsuite_src}  PARENT_SCOPE)
 set(tesh_files    ${tesh_files}     PARENT_SCOPE)
 set(xml_files     ${xml_files}      PARENT_SCOPE)
 
-foreach(x actor concurrent_rw pid)
+foreach(x actor concurrent_rw listen_async pid)
   ADD_TESH_FACTORIES(tesh-s4u-${x} "thread;boost;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x} --cd ${CMAKE_BINARY_DIR}/teshsuite/s4u/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x}/${x}.tesh)
 endforeach()
diff --git a/teshsuite/s4u/listen_async/listen_async.cpp b/teshsuite/s4u/listen_async/listen_async.cpp
new file mode 100644 (file)
index 0000000..4948ed4
--- /dev/null
@@ -0,0 +1,49 @@
+/* Bug report: https://github.com/simgrid/simgrid/issues/40
+ *
+ * Task.listen used to be on async mailboxes as it always returned false.
+ * This occures in Java and C, but is only tested here in C.
+ */
+
+#include "simgrid/s4u.hpp"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+
+static void server()
+{
+  simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName("mailbox");
+
+  simgrid::s4u::this_actor::isend(mailbox, xbt_strdup("Some data"), 0);
+
+  xbt_assert(mailbox->listen()); // True (1)
+  XBT_INFO("Task listen works on regular mailboxes");
+  char* res = static_cast<char*>(simgrid::s4u::this_actor::recv(mailbox));
+
+  xbt_assert(!strcmp("Some data", res), "Data received: %s", res);
+  XBT_INFO("Data successfully received from regular mailbox");
+  xbt_free(res);
+
+  simgrid::s4u::MailboxPtr mailbox2 = simgrid::s4u::Mailbox::byName("mailbox2");
+  mailbox2->setReceiver(simgrid::s4u::Actor::self());
+
+  simgrid::s4u::this_actor::isend(mailbox2, xbt_strdup("More data"), 0);
+
+  xbt_assert(mailbox2->listen()); // used to break.
+  XBT_INFO("Task listen works on asynchronous mailboxes");
+
+  res = static_cast<char*>(simgrid::s4u::this_actor::recv(mailbox2));
+  xbt_assert(!strcmp("More data", res));
+  xbt_free(res);
+
+  XBT_INFO("Data successfully received from asynchronous mailbox");
+}
+
+int main(int argc, char* argv[])
+{
+  simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
+  e->loadPlatform(argv[1]);
+
+  simgrid::s4u::Actor::createActor("test", simgrid::s4u::Host::by_name("Tremblay"), server);
+
+  e->run();
+  return 0;
+}
diff --git a/teshsuite/s4u/listen_async/listen_async.tesh b/teshsuite/s4u/listen_async/listen_async.tesh
new file mode 100644 (file)
index 0000000..184718e
--- /dev/null
@@ -0,0 +1,6 @@
+$ ./listen_async ${srcdir:=.}/../../../examples/platforms/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n"
+> [  0.000000] (test@Tremblay) Task listen works on regular mailboxes
+> [  0.000195] (test@Tremblay) Data successfully received from regular mailbox
+> [  0.000195] (test@Tremblay) Task listen works on asynchronous mailboxes
+> [  0.000195] (test@Tremblay) Data successfully received from asynchronous mailbox
+> [  0.000195] (maestro@) Variable 3 still in system when freing it: this may be a bug