1 /* Copyright (c) 2007-2016. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "src/kernel/activity/SynchroComm.hpp"
7 #include "src/surf/surf_interface.hpp"
8 #include "src/simix/smx_network_private.h"
9 #include "simgrid/modelchecker.h"
10 #include "src/mc/mc_replay.h"
12 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_network);
14 simgrid::kernel::activity::Comm::Comm(e_smx_comm_type_t _type) : type(_type)
16 state = SIMIX_WAITING;
20 XBT_DEBUG("Create communicate synchro %p", this);
23 simgrid::kernel::activity::Comm::~Comm()
25 XBT_DEBUG("Really free communication %p", this);
29 if (detached && state != SIMIX_DONE) {
30 /* the communication has failed and was detached:
31 * we have to free the buffer */
38 SIMIX_mbox_remove(mbox, this);
41 void simgrid::kernel::activity::Comm::suspend()
43 /* FIXME: shall we suspend also the timeout synchro? */
46 /* in the other case, the action will be suspended on creation, in SIMIX_comm_start() */
50 void simgrid::kernel::activity::Comm::resume()
52 /*FIXME: check what happen with the timeouts */
55 /* in the other case, the synchro were not really suspended yet, see SIMIX_comm_suspend() and SIMIX_comm_start() */
58 void simgrid::kernel::activity::Comm::cancel()
60 /* if the synchro is a waiting state means that it is still in a mbox */
61 /* so remove from it and delete it */
62 if (state == SIMIX_WAITING) {
63 SIMIX_mbox_remove(mbox, this);
64 state = SIMIX_CANCELED;
66 else if (!MC_is_active() /* when running the MC there are no surf actions */
67 && !MC_record_replay_is_active()
68 && (state == SIMIX_READY || state == SIMIX_RUNNING)) {
74 /** @brief get the amount remaining from the communication */
75 double simgrid::kernel::activity::Comm::remains()
77 if (state == SIMIX_RUNNING)
78 return surf_comm->getRemains();
80 /* FIXME: check what should be returned in the other cases */
84 /** @brief This is part of the cleanup process, probably an internal command */
85 void simgrid::kernel::activity::Comm::cleanupSurf()
94 src_timeout = nullptr;
99 dst_timeout = nullptr;
103 void simgrid::kernel::activity::Comm::post()
105 /* Update synchro state */
106 if (src_timeout && src_timeout->getState() == simgrid::surf::Action::State::done)
107 state = SIMIX_SRC_TIMEOUT;
108 else if (dst_timeout && dst_timeout->getState() == simgrid::surf::Action::State::done)
109 state = SIMIX_DST_TIMEOUT;
110 else if (src_timeout && src_timeout->getState() == simgrid::surf::Action::State::failed)
111 state = SIMIX_SRC_HOST_FAILURE;
112 else if (dst_timeout && dst_timeout->getState() == simgrid::surf::Action::State::failed)
113 state = SIMIX_DST_HOST_FAILURE;
114 else if (surf_comm && surf_comm->getState() == simgrid::surf::Action::State::failed) {
115 state = SIMIX_LINK_FAILURE;
119 XBT_DEBUG("SIMIX_post_comm: comm %p, state %d, src_proc %p, dst_proc %p, detached: %d",
120 this, (int)state, src_proc, dst_proc, detached);
122 /* destroy the surf actions associated with the Simix communication */
125 /* if there are simcalls associated with the synchro, then answer them */
126 if (!simcalls.empty())
127 SIMIX_comm_finish(this);