Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
74f8492059cd386c9bc8076da4aafe4c3b767645
[simgrid.git] / src / simix / SynchroComm.cpp
1 /* Copyright (c) 2007-2016. The SimGrid Team. All rights reserved.          */
2
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. */
5
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"
11
12 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_network);
13
14 simgrid::simix::Comm::Comm(e_smx_comm_type_t _type) {
15   state = SIMIX_WAITING;
16   this->type = _type;
17   refcount = 1;
18   src_data=NULL;
19   dst_data=NULL;
20
21   XBT_DEBUG("Create communicate synchro %p", this);
22 }
23 void simgrid::simix::Comm::suspend() {
24   /* FIXME: shall we suspend also the timeout synchro? */
25   if (surf_comm)
26     surf_comm->suspend();
27   /* in the other case, the action will be suspended on creation, in SIMIX_comm_start() */
28
29 }
30
31 void simgrid::simix::Comm::resume() {
32   /*FIXME: check what happen with the timeouts */
33   if (surf_comm)
34     surf_comm->resume();
35   /* in the other case, the synchro were not really suspended yet, see SIMIX_comm_suspend() and SIMIX_comm_start() */
36 }
37
38 void simgrid::simix::Comm::cancel() {
39   /* if the synchro is a waiting state means that it is still in a mbox */
40   /* so remove from it and delete it */
41   if (state == SIMIX_WAITING) {
42     SIMIX_mbox_remove(mbox, this);
43     state = SIMIX_CANCELED;
44   }
45   else if (!MC_is_active() /* when running the MC there are no surf actions */
46            && !MC_record_replay_is_active()
47            && (state == SIMIX_READY || state == SIMIX_RUNNING)) {
48
49     surf_comm->cancel();
50   }
51 }
52
53 /**  @brief get the amount remaining from the communication */
54 double simgrid::simix::Comm::remains() {
55   switch (state) {
56
57   case SIMIX_RUNNING:
58     return surf_comm->getRemains();
59     break;
60
61   case SIMIX_WAITING:
62   case SIMIX_READY:
63     return 0; /*FIXME: check what should be returned */
64     break;
65
66   default:
67     return 0; /*FIXME: is this correct? */
68     break;
69   }
70 }