Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
03390050990634e109b78ba198a5c90ce8c66b10
[simgrid.git] / src / kernel / activity / CommImpl.hpp
1 /* Copyright (c) 2007-2019. 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 #ifndef SIMGRID_KERNEL_ACTIVITY_COMM_HPP
7 #define SIMGRID_KERNEL_ACTIVITY_COMM_HPP
8
9 #include "src/kernel/activity/ActivityImpl.hpp"
10 #include "src/kernel/actor/ActorImpl.hpp"
11 #include "surf/surf.hpp"
12
13
14 namespace simgrid {
15 namespace kernel {
16 namespace activity {
17
18 class XBT_PUBLIC CommImpl : public ActivityImpl_T<CommImpl> {
19   ~CommImpl() override;
20   void cleanupSurf();
21
22   double rate_ = 0.0;
23   double size_ = 0.0;
24
25 public:
26   enum class Type { SEND = 0, RECEIVE, READY, DONE };
27
28   CommImpl& set_type(CommImpl::Type type);
29   CommImpl& set_size(double size);
30   double get_rate() { return rate_; }
31   CommImpl& set_rate(double rate);
32   CommImpl& set_src_buff(void* buff, size_t size);
33   CommImpl& set_dst_buff(void* buff, size_t* size);
34
35   CommImpl* start();
36   void copy_data();
37   void suspend() override;
38   void resume() override;
39   void post() override;
40   void finish() override;
41   void cancel();
42
43   CommImpl::Type type_;        /* Type of the communication (SIMIX_COMM_SEND or SIMIX_COMM_RECEIVE) */
44   MailboxImpl* mbox = nullptr; /* Rendez-vous where the comm is queued */
45
46 #if SIMGRID_HAVE_MC
47   MailboxImpl* mbox_cpy = nullptr; /* Copy of the rendez-vous where the comm is queued, MC needs it for DPOR
48                                      (comm.mbox set to nullptr when the communication is removed from the mailbox
49                                      (used as garbage collector)) */
50 #endif
51   bool detached_ = false; /* If detached or not */
52
53   void (*clean_fun)(void*) = nullptr; /* Function to clean the detached src_buf if something goes wrong */
54   int (*match_fun)(void*, void*, CommImpl*) = nullptr; /* Filter function used by the other side. It is used when
55 looking if a given communication matches my needs. For that, myself must match the
56 expectations of the other side, too. See  */
57   void (*copy_data_fun)(CommImpl*, void*, size_t) = nullptr;
58
59   /* Surf action data */
60   resource::Action* src_timeout_ = nullptr; /* Surf's actions to instrument the timeouts */
61   resource::Action* dst_timeout_ = nullptr; /* Surf's actions to instrument the timeouts */
62   actor::ActorImplPtr src_actor_ = nullptr;
63   actor::ActorImplPtr dst_actor_ = nullptr;
64
65   /* Data to be transfered */
66   void* src_buff_        = nullptr;
67   void* dst_buff_        = nullptr;
68   size_t src_buff_size_  = 0;
69   size_t* dst_buff_size_ = nullptr;
70   bool copied           = false; /* whether the data were already copied */
71
72   void* src_data_ = nullptr; /* User data associated to the communication */
73   void* dst_data_ = nullptr;
74 };
75 } // namespace activity
76 } // namespace kernel
77 } // namespace simgrid
78
79 #endif