1 /* Copyright (c) 2006-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "msg/msg_private.h"
9 #include "msg/msg_mailbox.h"
11 #include "simgrid/s4u/comm.hpp"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_comm,s4u_async,"S4U asynchronous communications");
14 using namespace simgrid;
20 s4u::Comm &s4u::Comm::send_init(s4u::Actor *sender, s4u::Mailbox &chan) {
21 s4u::Comm *res = new s4u::Comm();
22 res->p_sender = sender;
23 res->p_mailbox = &chan;
28 void s4u::Comm::setRate(double rate) {
29 xbt_assert(p_state==inited);
33 void s4u::Comm::setSrcData(void * buff) {
34 xbt_assert(p_state==inited);
37 void s4u::Comm::setSrcDataSize(size_t size){
38 xbt_assert(p_state==inited);
41 void s4u::Comm::setSrcData(void * buff, size_t size) {
42 xbt_assert(p_state==inited);
48 void s4u::Comm::start() {
49 xbt_assert(p_state == inited);
51 p_inferior = simcall_comm_isend(p_sender->getInferior(), p_mailbox->getInferior(), p_remains, p_rate,
52 p_srcBuff, p_srcBuffSize,
53 p_matchFunction, p_cleanFunction, p_copyDataFunction,
54 p_userData, p_detached);
57 void s4u::Comm::wait() {
58 xbt_assert(p_state == started || p_state == inited);
60 if (p_state == started)
61 simcall_comm_wait(p_inferior, -1/*timeout*/);
62 else // p_state == inited
63 /* Save a simcall and do directly a blocking send */
64 simcall_comm_send(p_sender->getInferior(), p_mailbox->getInferior(), p_remains, p_rate,
65 p_srcBuff, p_srcBuffSize,
66 p_matchFunction, p_copyDataFunction,
67 p_userData, p_detached);
70 void s4u::Comm::wait(double timeout) {
71 xbt_assert(p_state == started || p_state == inited);
73 if (p_state == inited)
75 simcall_comm_wait(p_inferior, timeout);
78 s4u::Comm &s4u::Comm::send_async(s4u::Actor *sender, Mailbox &dest, void *data, int simulatedSize) {
79 s4u::Comm &res = s4u::Comm::send_init(sender, dest);
81 res.setRemains(simulatedSize);
83 res.p_srcBuffSize = sizeof(void*);