Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make msg_mailbox_t be the s4u::Mailbox
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 31 Jul 2016 11:26:04 +0000 (13:26 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 31 Jul 2016 11:31:51 +0000 (13:31 +0200)
This forces me to make s4u::Mailbox->getImpl() public because I don't
manage to pass intrusive_ptr<s4u::Mailbox> as arguments to simcalls...

I really need to work on my C++-fu

include/simgrid/forward.h
include/simgrid/msg.h
include/simgrid/s4u/mailbox.hpp
src/msg/msg_gos.cpp
src/msg/msg_mailbox.cpp

index 67212b1..63f3269 100644 (file)
@@ -9,6 +9,8 @@
 
 #ifdef __cplusplus
 
+#include <boost/intrusive_ptr.hpp>
+
 namespace simgrid {
   namespace s4u {
     class As;
@@ -36,7 +38,7 @@ namespace simgrid {
 
 typedef simgrid::s4u::As simgrid_As;
 typedef simgrid::s4u::Host simgrid_Host;
-typedef simgrid::s4u::Mailbox simgrid_Mailbox;
+typedef boost::intrusive_ptr<simgrid::s4u::Mailbox> sg_mbox_t;
 typedef simgrid::kernel::activity::Synchro simgrid_Synchro;
 typedef simgrid::kernel::routing::NetCard routing_NetCard;
 typedef simgrid::surf::Cpu surf_Cpu;
@@ -48,7 +50,7 @@ typedef simgrid::trace_mgr::trace tmgr_Trace;
 
 typedef struct simgrid_As   simgrid_As;
 typedef struct simgrid_Host simgrid_Host;
-typedef struct simgrid_Mailbox simgrid_Mailbox;
+typedef struct simgrid_Mailbox *sg_mbox_t;
 typedef struct simgrid_Synchro simgrid_Synchro;
 typedef struct surf_Cpu surf_Cpu;
 typedef struct routing_NetCard routing_NetCard;
@@ -59,7 +61,6 @@ typedef struct Trace tmgr_Trace;
 
 typedef simgrid_As *AS_t;
 typedef simgrid_Host* sg_host_t;
-typedef simgrid_Mailbox* sg_mbox_t;
 
 typedef simgrid_Synchro *smx_synchro_t;
 
index 292a67d..8b0e2f1 100644 (file)
@@ -26,7 +26,7 @@ SG_BEGIN_DECL()
  * #MSG_task_send and friends) hide this object behind a string
  * alias. That mean that you don't provide the mailbox on which you
  * want to send your task, but only the name of this mailbox. */
-typedef smx_mailbox_t msg_mailbox_t;
+typedef sg_mbox_t msg_mailbox_t;
 
 /* ******************************** Environment ************************************ */
 typedef simgrid_As *msg_as_t;
index f26266a..63864ad 100644 (file)
@@ -34,10 +34,8 @@ XBT_PUBLIC_CLASS Mailbox {
 
   Mailbox(smx_mailbox_t mbox): pimpl_(mbox) {}
 
-protected:
-  smx_mailbox_t getImpl() { return pimpl_; }
-
 public:
+  smx_mailbox_t getImpl() { return pimpl_; } // FIXME: make me protected
 
   // We don't have to manage the lifetime of mailboxes:
   friend void intrusive_ptr_add_ref(Mailbox*) {}
index f036d97..1d0131f 100644 (file)
@@ -295,7 +295,7 @@ static inline msg_comm_t MSG_task_isend_internal(msg_task_t task, const char *al
   msg_global->sent_msg++;
 
   /* Send it by calling SIMIX network layer */
-  smx_synchro_t act = simcall_comm_isend(myself, mailbox, t_simdata->bytes_amount, t_simdata->rate,
+  smx_synchro_t act = simcall_comm_isend(myself, mailbox->getImpl(), t_simdata->bytes_amount, t_simdata->rate,
                                          task, sizeof(void *), match_fun, cleanup, nullptr, match_data,detached);
   t_simdata->comm = static_cast<simgrid::kernel::activity::Comm*>(act);
 
@@ -435,7 +435,7 @@ msg_comm_t MSG_task_irecv(msg_task_t *task, const char *name)
  */
 msg_comm_t MSG_task_irecv_bounded(msg_task_t *task, const char *name, double rate)
 {
-  smx_mailbox_t rdv = MSG_mailbox_get_by_alias(name);
+  msg_mailbox_t mbox = MSG_mailbox_get_by_alias(name);
 
   /* FIXME: these functions are not traceable */
   /* Sanity check */
@@ -449,7 +449,7 @@ msg_comm_t MSG_task_irecv_bounded(msg_task_t *task, const char *name, double rat
   comm->task_sent = nullptr;
   comm->task_received = task;
   comm->status = MSG_OK;
-  comm->s_comm = simcall_comm_irecv(MSG_process_self(), rdv, task, nullptr, nullptr, nullptr, nullptr, rate);
+  comm->s_comm = simcall_comm_irecv(MSG_process_self(), mbox->getImpl(), task, nullptr, nullptr, nullptr, nullptr, rate);
 
   return comm;
 }
@@ -776,7 +776,7 @@ msg_error_t MSG_task_send_with_timeout(msg_task_t task, const char *alias, doubl
   /* Try to send it by calling SIMIX network layer */
   try {
     smx_synchro_t comm = nullptr; /* MC needs the comm to be set to nullptr during the simix call  */
-    comm = simcall_comm_isend(SIMIX_process_self(), mailbox,t_simdata->bytes_amount,
+    comm = simcall_comm_isend(SIMIX_process_self(), mailbox->getImpl(),t_simdata->bytes_amount,
                               t_simdata->rate, task, sizeof(void *), nullptr, nullptr, nullptr, task, 0);
     if (TRACE_is_enabled())
       simcall_set_category(comm, task->category);
@@ -836,9 +836,9 @@ msg_error_t MSG_task_send_with_timeout_bounded(msg_task_t task, const char *alia
  */
 int MSG_task_listen(const char *alias)
 {
-  smx_mailbox_t mbox = MSG_mailbox_get_by_alias(alias);
+  msg_mailbox_t mbox = MSG_mailbox_get_by_alias(alias);
   return !MSG_mailbox_is_empty(mbox) ||
-    (mbox->permanent_receiver && !mbox->done_comm_queue.empty());
+    (mbox->getImpl()->permanent_receiver && !mbox->getImpl()->done_comm_queue.empty());
 }
 
 /** \ingroup msg_task_usage
@@ -852,7 +852,7 @@ int MSG_task_listen(const char *alias)
 int MSG_task_listen_from(const char *alias)
 {
   msg_mailbox_t mbox = MSG_mailbox_get_by_alias(alias);
-  simgrid::kernel::activity::Comm* comm = static_cast<simgrid::kernel::activity::Comm*>(simcall_mbox_front(mbox));
+  simgrid::kernel::activity::Comm* comm = static_cast<simgrid::kernel::activity::Comm*>(simcall_mbox_front(mbox->getImpl()));
 
   if (!comm)
     return -1;
index d463698..2119287 100644 (file)
 
 #include "simgrid/msg.h"
 #include "msg_private.h"
+#include "simgrid/s4u/mailbox.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_mailbox, msg, "Logging specific to MSG (mailbox)");
 
 int MSG_mailbox_is_empty(msg_mailbox_t mailbox)
 {
-  return (nullptr == simcall_mbox_front(mailbox));
+  return mailbox->empty();
 }
 
 msg_task_t MSG_mailbox_front(msg_mailbox_t mailbox)
 {
-  simgrid::kernel::activity::Comm* comm = static_cast<simgrid::kernel::activity::Comm*>(simcall_mbox_front(mailbox));
+  simgrid::kernel::activity::Comm* comm = static_cast<simgrid::kernel::activity::Comm*>(simcall_mbox_front(mailbox->getImpl()));
 
   if (!comm)
     return nullptr;
@@ -30,12 +31,7 @@ msg_task_t MSG_mailbox_front(msg_mailbox_t mailbox)
 
 msg_mailbox_t MSG_mailbox_get_by_alias(const char *alias)
 {
-  msg_mailbox_t mailbox = simcall_mbox_get_by_name(alias);
-
-  if (!mailbox)
-    mailbox = simcall_mbox_create(alias);
-
-  return mailbox;
+  return simgrid::s4u::Mailbox::byName(alias);
 }
 
 /** \ingroup msg_mailbox_management
@@ -50,7 +46,7 @@ msg_mailbox_t MSG_mailbox_get_by_alias(const char *alias)
 void MSG_mailbox_set_async(const char *alias){
   msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
 
-  simcall_mbox_set_receiver(mailbox, SIMIX_process_self());
+  simcall_mbox_set_receiver(mailbox->getImpl(), SIMIX_process_self());
   XBT_VERB("%s mailbox set to receive eagerly for myself\n",alias);
 }
 
@@ -103,7 +99,7 @@ msg_error_t MSG_mailbox_get_task_ext_bounded(msg_mailbox_t mailbox, msg_task_t *
 
   /* Try to receive it by calling SIMIX network layer */
   try {
-    simcall_comm_recv(MSG_process_self(), mailbox, task, nullptr, nullptr, nullptr, nullptr, timeout, rate);
+    simcall_comm_recv(MSG_process_self(), mailbox->getImpl(), task, nullptr, nullptr, nullptr, nullptr, timeout, rate);
     XBT_DEBUG("Got task %s from %p",(*task)->name,mailbox);
     (*task)->simdata->setNotUsed();
   }