-void s4u::Comm::start() {
- xbt_assert(p_state == inited);
-
- if (p_srcBuff != NULL) { // Sender side
- p_inferior = simcall_comm_isend(p_sender->getInferior(), p_mailbox->getInferior(), p_remains, p_rate,
- p_srcBuff, p_srcBuffSize,
- p_matchFunction, p_cleanFunction, p_copyDataFunction,
- p_userData, p_detached);
- } else if (p_dstBuff != NULL) { // Receiver side
- p_inferior = simcall_comm_irecv(p_mailbox->getInferior(), p_dstBuff, &p_dstBuffSize,
- p_matchFunction, p_copyDataFunction,
- p_userData, p_rate);
-
- } else {
- xbt_die("Cannot start a communication before specifying whether we are the sender or the receiver");
- }
- p_state = started;
+void Comm::start() {
+ xbt_assert(state_ == inited);
+
+ if (srcBuff_ != nullptr) { // Sender side
+ pimpl_ = simcall_comm_isend(sender_, mailbox_->getInferior(), remains_, rate_,
+ srcBuff_, srcBuffSize_,
+ matchFunction_, cleanFunction_, copyDataFunction_,
+ userData_, detached_);
+ } else if (dstBuff_ != nullptr) { // Receiver side
+ pimpl_ = simcall_comm_irecv(receiver_, mailbox_->getInferior(), dstBuff_, &dstBuffSize_,
+ matchFunction_, copyDataFunction_,
+ userData_, rate_);
+
+ } else {
+ xbt_die("Cannot start a communication before specifying whether we are the sender or the receiver");
+ }
+ state_ = started;
+}
+void Comm::wait() {
+ xbt_assert(state_ == started || state_ == inited);
+
+ if (state_ == started)
+ simcall_comm_wait(pimpl_, -1/*timeout*/);
+ else {// p_state == inited. Save a simcall and do directly a blocking send/recv
+ if (srcBuff_ != nullptr) {
+ simcall_comm_send(sender_, mailbox_->getInferior(), remains_, rate_,
+ srcBuff_, srcBuffSize_,
+ matchFunction_, copyDataFunction_,
+ userData_, -1 /*timeout*/);
+ } else {
+ simcall_comm_recv(receiver_, mailbox_->getInferior(), dstBuff_, &dstBuffSize_,
+ matchFunction_, copyDataFunction_,
+ userData_, -1/*timeout*/, rate_);
+ }
+ }
+ state_ = finished;
+}
+void Comm::wait(double timeout) {
+ xbt_assert(state_ == started || state_ == inited);
+
+ if (state_ == started) {
+ simcall_comm_wait(pimpl_, timeout);
+ state_ = finished;
+ return;
+ }
+
+ // It's not started yet. Do it in one simcall
+ if (srcBuff_ != nullptr) {
+ simcall_comm_send(sender_, mailbox_->getInferior(), remains_, rate_,
+ srcBuff_, srcBuffSize_,
+ matchFunction_, copyDataFunction_,
+ userData_, timeout);
+ } else { // Receiver
+ simcall_comm_recv(receiver_, mailbox_->getInferior(), dstBuff_, &dstBuffSize_,
+ matchFunction_, copyDataFunction_,
+ userData_, timeout, rate_);
+ }
+ state_ = finished;