Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove some half baken functions cluttering the mailboxes
[simgrid.git] / src / simix / smx_network.cpp
index b3d4c06..6401465 100644 (file)
 #include "mc/mc.h"
 #include "src/mc/mc_replay.h"
 #include "xbt/dict.h"
+#include "simgrid/s4u/mailbox.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_network, simix, "SIMIX network-related synchronization");
 
-static xbt_dict_t mailboxes = NULL;
-XBT_EXPORT_NO_IMPORT(unsigned long int) smx_total_comms = 0;
+static void SIMIX_mbox_free(void *data);
+static xbt_dict_t mailboxes = xbt_dict_new_homogeneous(SIMIX_mbox_free);
 
 static void SIMIX_waitany_remove_simcall_from_actions(smx_simcall_t simcall);
 static void SIMIX_comm_copy_data(smx_synchro_t comm);
@@ -26,15 +27,9 @@ static smx_synchro_t SIMIX_fifo_probe_comm(xbt_fifo_t fifo, e_smx_comm_type_t ty
 static smx_synchro_t SIMIX_fifo_get_comm(xbt_fifo_t fifo, e_smx_comm_type_t type,
                                         int (*match_fun)(void *, void *,smx_synchro_t),
                                         void *user_data, smx_synchro_t my_synchro);
-static void SIMIX_mbox_free(void *data);
 static void SIMIX_comm_start(smx_synchro_t synchro);
 
-void SIMIX_network_init(void)
-{
-  mailboxes = xbt_dict_new_homogeneous(SIMIX_mbox_free);
-}
-
-void SIMIX_network_exit(void)
+void SIMIX_mailbox_exit(void)
 {
   xbt_dict_free(&mailboxes);
 }
@@ -45,30 +40,23 @@ void SIMIX_network_exit(void)
 
 smx_mailbox_t SIMIX_mbox_create(const char *name)
 {
+  xbt_assert(name, "Mailboxes must have a name");
   /* two processes may have pushed the same mbox_create simcall at the same time */
-  smx_mailbox_t mbox = name ? (smx_mailbox_t) xbt_dict_get_or_null(mailboxes, name) : NULL;
+  smx_mailbox_t mbox = (smx_mailbox_t) xbt_dict_get_or_null(mailboxes, name);
 
   if (!mbox) {
     mbox = xbt_new0(s_smx_mailbox_t, 1);
-    mbox->name = name ? xbt_strdup(name) : NULL;
+    mbox->name = xbt_strdup(name);
     mbox->comm_fifo = xbt_fifo_new();
     mbox->done_comm_fifo = xbt_fifo_new();
     mbox->permanent_receiver=NULL;
 
     XBT_DEBUG("Creating a mailbox at %p with name %s", mbox, name);
-
-    if (mbox->name)
-      xbt_dict_set(mailboxes, mbox->name, mbox, NULL);
+    xbt_dict_set(mailboxes, mbox->name, mbox, NULL);
   }
   return mbox;
 }
 
-void SIMIX_mbox_destroy(smx_mailbox_t mbox)
-{
-  if (mbox->name)
-    xbt_dict_remove(mailboxes, mbox->name);
-}
-
 void SIMIX_mbox_free(void *data)
 {
   XBT_DEBUG("mbox free %p", data);
@@ -80,30 +68,11 @@ void SIMIX_mbox_free(void *data)
   xbt_free(mbox);
 }
 
-xbt_dict_t SIMIX_get_mailboxes()
-{
-  return mailboxes;
-}
-
 smx_mailbox_t SIMIX_mbox_get_by_name(const char *name)
 {
   return (smx_mailbox_t) xbt_dict_get_or_null(mailboxes, name);
 }
 
-int SIMIX_mbox_comm_count_by_host(smx_mailbox_t mbox, sg_host_t host)
-{
-  smx_synchro_t comm = NULL;
-  xbt_fifo_item_t item = NULL;
-  int count = 0;
-
-  xbt_fifo_foreach(mbox->comm_fifo, item, comm, smx_synchro_t) {
-    if (comm->comm.src_proc->host == host)
-      count++;
-  }
-
-  return count;
-}
-
 smx_synchro_t SIMIX_mbox_get_head(smx_mailbox_t mbox)
 {
   return (smx_synchro_t) xbt_fifo_get_item_content(
@@ -255,7 +224,6 @@ smx_synchro_t SIMIX_comm_new(e_smx_comm_type_t type)
   synchro->category = NULL;
 
   XBT_DEBUG("Create communicate synchro %p", synchro);
-  ++smx_total_comms;
 
   return synchro;
 }
@@ -366,7 +334,6 @@ smx_synchro_t simcall_HANDLER_comm_isend(smx_simcall_t simcall, smx_process_t sr
     XBT_DEBUG("Receive already pushed");
 
     SIMIX_comm_destroy(this_synchro);
-    --smx_total_comms; // this creation was a pure waste
 
     other_synchro->state = SIMIX_READY;
     other_synchro->comm.type = SIMIX_COMM_READY;
@@ -455,7 +422,6 @@ smx_synchro_t SIMIX_comm_irecv(smx_process_t dst_proc, smx_mailbox_t mbox, void
       }
       other_synchro->comm.refcount--;
       SIMIX_comm_destroy(this_synchro);
-      --smx_total_comms; // this creation was a pure waste
     }
   } else {
     /* Prepare a synchro describing us, so that it gets passed to the user-provided filter of other side */
@@ -472,7 +438,6 @@ smx_synchro_t SIMIX_comm_irecv(smx_process_t dst_proc, smx_mailbox_t mbox, void
       SIMIX_mbox_push(mbox, this_synchro);
     } else {
       SIMIX_comm_destroy(this_synchro);
-      --smx_total_comms; // this creation was a pure waste
       other_synchro->state = SIMIX_READY;
       other_synchro->comm.type = SIMIX_COMM_READY;
       //other_synchro->comm.refcount--;
@@ -541,7 +506,6 @@ smx_synchro_t SIMIX_comm_iprobe(smx_process_t dst_proc, smx_mailbox_t mbox, int
   if(other_synchro)other_synchro->comm.refcount--;
 
   SIMIX_comm_destroy(this_synchro);
-  --smx_total_comms;
   return other_synchro;
 }