#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;
+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);
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);
}
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);
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(