+ smx_action_t action;
+
+ /* Look for communication request matching our needs.
+ * If it is not found then create it and push it into the rendez-vous point
+ */
+ action = SIMIX_rdv_get_request(rdv, SIMIX_COMM_SEND, match_fun, data);
+
+ if (!action) {
+ action = SIMIX_comm_new(SIMIX_COMM_RECEIVE);
+ SIMIX_rdv_push(rdv, action);
+ } else {
+ action->state = SIMIX_READY;
+ action->comm.type = SIMIX_COMM_READY;
+ }
+
+ /* Setup communication request */
+ action->comm.dst_proc = dst_proc;
+ action->comm.dst_buff = dst_buff;
+ action->comm.dst_buff_size = dst_buff_size;
+ action->comm.dst_data = data;
+
+ if (MC_IS_ENABLED) {
+ action->state = SIMIX_RUNNING;
+ return action;
+ }
+
+ SIMIX_comm_start(action);
+ return action;
+}
+
+void SIMIX_pre_comm_wait(smx_req_t req, smx_action_t action, double timeout, int idx)
+{
+ /* the request may be a wait, a send or a recv */
+ surf_action_t sleep;
+
+ /* Associate this request to the action */
+ xbt_fifo_push(action->request_list, req);
+ req->issuer->waiting_action = action;
+
+ if (MC_IS_ENABLED) {
+ if (idx == 0) {
+ action->state = SIMIX_DONE;
+ } else {
+ /* If we reached this point, the wait request must have a timeout */
+ /* Otherwise it shouldn't be enabled and executed by the MC */
+ if (timeout == -1)
+ THROW_IMPOSSIBLE;
+
+ if (action->comm.src_proc == req->issuer)
+ action->state = SIMIX_SRC_TIMEOUT;
+ else
+ action->state = SIMIX_DST_TIMEOUT;
+ }
+
+ SIMIX_comm_finish(action);
+ return;
+ }
+
+ /* If the action has already finish perform the error handling, */
+ /* otherwise set up a waiting timeout on the right side */
+ if (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING) {
+ SIMIX_comm_finish(action);
+ } else { /* if (timeout >= 0) { we need a surf sleep action even when there is no timeout, otherwise surf won't tell us when the host fails */
+ sleep = surf_workstation_model->extension.workstation.sleep(req->issuer->smx_host->host, timeout);
+ surf_workstation_model->action_data_set(sleep, action);
+
+ if (req->issuer == action->comm.src_proc)
+ action->comm.src_timeout = sleep;
+ else
+ action->comm.dst_timeout = sleep;
+ }
+}
+
+void SIMIX_pre_comm_test(smx_req_t req)
+{
+ smx_action_t action = req->comm_test.comm;
+
+ if(MC_IS_ENABLED){
+ req->comm_test.result = action->comm.src_proc && action->comm.dst_proc;
+ if(req->comm_test.result){
+ action->state = SIMIX_DONE;
+ xbt_fifo_push(action->request_list, req);
+ SIMIX_comm_finish(action);
+ }else{
+ SIMIX_request_answer(req);
+ }
+ return;
+ }
+
+ req->comm_test.result = (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING);
+ if (req->comm_test.result) {
+ xbt_fifo_push(action->request_list, req);
+ SIMIX_comm_finish(action);
+ } else {
+ SIMIX_request_answer(req);
+ }
+}
+
+void SIMIX_pre_comm_testany(smx_req_t req, int idx)
+{
+ unsigned int cursor;
+ smx_action_t action;
+ xbt_dynar_t actions = req->comm_testany.comms;
+ req->comm_testany.result = -1;
+
+ if (MC_IS_ENABLED){
+ if(idx == -1){
+ SIMIX_request_answer(req);
+ }else{
+ action = xbt_dynar_get_as(actions, idx, smx_action_t);
+ req->comm_testany.result = idx;
+ xbt_fifo_push(action->request_list, req);
+ action->state = SIMIX_DONE;
+ SIMIX_comm_finish(action);
+ }
+ return;
+ }
+
+ xbt_dynar_foreach(req->comm_testany.comms,cursor,action) {
+ if (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING) {
+ req->comm_testany.result = cursor;
+ xbt_fifo_push(action->request_list, req);
+ SIMIX_comm_finish(action);
+ return;
+ }
+ }
+ SIMIX_request_answer(req);
+}
+
+void SIMIX_pre_comm_waitany(smx_req_t req, int idx)
+{
+ smx_action_t action;
+ unsigned int cursor = 0;
+ xbt_dynar_t actions = req->comm_waitany.comms;
+
+ if (MC_IS_ENABLED){
+ action = xbt_dynar_get_as(actions, idx, smx_action_t);
+ xbt_fifo_push(action->request_list, req);
+ req->comm_waitany.result = idx;
+ action->state = SIMIX_DONE;
+ SIMIX_comm_finish(action);
+ return;
+ }
+
+ xbt_dynar_foreach(actions, cursor, action){
+ /* Associate this request to the action */
+ xbt_fifo_push(action->request_list, req);
+ if (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING){
+ SIMIX_comm_finish(action);
+ break;
+ }
+ }
+}
+
+void SIMIX_waitany_req_remove_from_actions(smx_req_t req)
+{
+ smx_action_t action;
+ unsigned int cursor = 0;
+ xbt_dynar_t actions = req->comm_waitany.comms;
+
+ xbt_dynar_foreach(actions, cursor, action){
+ xbt_fifo_remove(action->request_list, req);
+ }