*/
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();
/** 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();
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
c.wait();
}
+void isend(MailboxPtr chan, void* payload, double simulatedSize)
+{
+ Comm::send_async(chan, payload, simulatedSize);
+}
+
int pid()
{
return SIMIX_process_self()->pid;
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();
# 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)
${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()
+++ /dev/null
-/* 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;
-}
+++ /dev/null
-$ ./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
-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})
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()
--- /dev/null
+/* 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;
+}
--- /dev/null
+$ ./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