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/simix/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::simix::Comm::Comm(e_smx_comm_type_t _type) {
15 state = SIMIX_WAITING;
21 XBT_DEBUG("Create communicate synchro %p", this);
23 void simgrid::simix::Comm::suspend()
25 /* FIXME: shall we suspend also the timeout synchro? */
28 /* in the other case, the action will be suspended on creation, in SIMIX_comm_start() */
32 void simgrid::simix::Comm::resume()
34 /*FIXME: check what happen with the timeouts */
37 /* in the other case, the synchro were not really suspended yet, see SIMIX_comm_suspend() and SIMIX_comm_start() */
40 void simgrid::simix::Comm::cancel()
42 /* if the synchro is a waiting state means that it is still in a mbox */
43 /* so remove from it and delete it */
44 if (state == SIMIX_WAITING) {
45 SIMIX_mbox_remove(mbox, this);
46 state = SIMIX_CANCELED;
48 else if (!MC_is_active() /* when running the MC there are no surf actions */
49 && !MC_record_replay_is_active()
50 && (state == SIMIX_READY || state == SIMIX_RUNNING)) {
56 /** @brief get the amount remaining from the communication */
57 double simgrid::simix::Comm::remains()
62 return surf_comm->getRemains();
67 return 0; /*FIXME: check what should be returned */
71 return 0; /*FIXME: is this correct? */
76 void simgrid::simix::Comm::unref()
78 XBT_DEBUG("Destroy synchro %p (refcount: %d), state: %d", this, refcount, (int)state);
80 xbt_assert(refcount > 0,
81 "This comm has a negative refcount! You must not call test() or wait() more than once on a given communication.");
86 XBT_DEBUG("Really free communication %p; refcount is now %d", this, refcount);
90 if (detached && state != SIMIX_DONE) {
91 /* the communication has failed and was detached:
92 * we have to free the buffer */
99 SIMIX_mbox_remove(mbox, this);
104 /** @brief This is part of the cleanup process, probably an internal command */
105 void simgrid::simix::Comm::cleanupSurf()
113 src_timeout->unref();
118 dst_timeout->unref();