3 /* Copyright (c) 2008, 2009, 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "msg_mailbox.h"
10 #include "msg_private.h"
11 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_mailbox, msg,
12 "Logging specific to MSG (mailbox)");
14 msg_mailbox_t MSG_mailbox_new(const char *alias)
16 return simcall_rdv_create(alias);
19 void MSG_mailbox_free(void *mailbox)
21 simcall_rdv_destroy((msg_mailbox_t)mailbox);
24 int MSG_mailbox_is_empty(msg_mailbox_t mailbox)
26 return (NULL == simcall_rdv_get_head(mailbox));
29 m_task_t MSG_mailbox_get_head(msg_mailbox_t mailbox)
31 smx_action_t comm = simcall_rdv_get_head(mailbox);
36 return (m_task_t) simcall_comm_get_src_data(comm);
40 MSG_mailbox_get_count_host_waiting_tasks(msg_mailbox_t mailbox,
43 return simcall_rdv_comm_count_by_host(mailbox,
47 msg_mailbox_t MSG_mailbox_get_by_alias(const char *alias)
50 msg_mailbox_t mailbox = simcall_rdv_get_by_name(alias);
53 mailbox = MSG_mailbox_new(alias);
59 MSG_mailbox_get_task_ext(msg_mailbox_t mailbox, m_task_t * task,
60 m_host_t host, double timeout)
63 MSG_error_t ret = MSG_OK;
64 /* We no longer support getting a task from a specific host */
69 TRACE_msg_task_get_start();
70 volatile double start_time = MSG_get_clock();
74 xbt_assert(task, "Null pointer for the task storage");
78 ("Asked to write the received task in a non empty struct -- proceeding.");
80 /* Try to receive it by calling SIMIX network layer */
82 simcall_comm_recv(mailbox, task, NULL, NULL, NULL, timeout);
83 XBT_DEBUG("Got task %s from %p",(*task)->name,mailbox);
84 (*task)->simdata->isused=0;
89 ret = MSG_HOST_FAILURE;
92 ret = MSG_TRANSFER_FAILURE;
104 if (ret != MSG_HOST_FAILURE &&
105 ret != MSG_TRANSFER_FAILURE &&
106 ret != MSG_TIMEOUT) {
107 TRACE_msg_task_get_end(start_time, *task);
114 MSG_mailbox_put_with_timeout(msg_mailbox_t mailbox, m_task_t task,
118 MSG_error_t ret = MSG_OK;
119 simdata_task_t t_simdata = NULL;
120 m_process_t process = MSG_process_self();
121 simdata_process_t p_simdata = SIMIX_process_self_get_data(process);
124 int call_end = TRACE_msg_task_put_start(task); //must be after CHECK_HOST()
127 /* Prepare the task to send */
128 t_simdata = task->simdata;
129 t_simdata->sender = process;
130 t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host;
132 xbt_assert(t_simdata->isused == 0,
133 "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
136 t_simdata->comm = NULL;
137 msg_global->sent_msg++;
140 p_simdata->waiting_task = task;
142 /* Try to send it by calling SIMIX network layer */
144 smx_action_t comm = simcall_comm_isend(mailbox, t_simdata->message_size,
145 t_simdata->rate, task, sizeof(void *),
146 NULL, NULL, task, 0);
148 if (TRACE_is_enabled()) {
149 simcall_set_category(comm, task->category);
152 t_simdata->comm = comm;
153 simcall_comm_wait(comm, timeout);
157 switch (e.category) {
159 ret = MSG_HOST_FAILURE;
162 ret = MSG_TRANSFER_FAILURE;
172 /* If the send failed, it is not used anymore */
173 t_simdata->isused = 0;
177 p_simdata->waiting_task = NULL;
180 TRACE_msg_task_put_end();
185 #ifdef MSG_USE_DEPRECATED
186 msg_mailbox_t MSG_mailbox_get_by_channel(m_host_t host,
189 XBT_WARN("DEPRECATED! Now use MSG_mailbox_get_by_alias");
190 xbt_assert((host != NULL), "Invalid host");
191 xbt_assert((channel >= 0)
192 && (channel < msg_global->max_channel), "Invalid channel %d",
195 return host->simdata->mailboxes[(size_t) channel];