Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
merge with framagit/master
[simgrid.git] / src / kernel / activity / CommImpl.hpp
1 /* Copyright (c) 2007-2021. 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 cleanup_surf();
21
22   double rate_       = 0.0;
23   double size_       = 0.0;
24   bool detached_     = false;   /* If detached or not */
25   bool copied_       = false;   /* whether the data were already copied */
26   MailboxImpl* mbox_ = nullptr; /* Rendez-vous where the comm is queued */
27
28 public:
29   enum class Type { SEND, RECEIVE };
30
31   CommImpl(Type type) : type_(type) {}
32   CommImpl(s4u::Host* from, s4u::Host* to, double bytes);
33
34   CommImpl& set_size(double size);
35   CommImpl& set_src_buff(unsigned char* buff, size_t size);
36   CommImpl& set_dst_buff(unsigned char* buff, size_t* size);
37   CommImpl& set_rate(double rate);
38   CommImpl& set_mailbox(MailboxImpl* mbox);
39   CommImpl& detach();
40
41   double get_rate() const { return rate_; }
42   MailboxImpl* get_mailbox() const { return mbox_; }
43   bool detached() const { return detached_; }
44
45   void copy_data();
46
47   CommImpl* start();
48   void suspend() override;
49   void resume() override;
50   void cancel() override;
51   void post() override;
52   void finish() override;
53
54   const CommImpl::Type type_; /* Type of the communication (SEND or RECEIVE) */
55
56 #if SIMGRID_HAVE_MC
57   MailboxImpl* mbox_cpy = nullptr; /* Copy of the rendez-vous where the comm is queued, MC needs it for DPOR
58                                      (comm.mbox set to nullptr when the communication is removed from the mailbox
59                                      (used as garbage collector)) */
60 #endif
61
62   void (*clean_fun)(void*) = nullptr; /* Function to clean the detached src_buf if something goes wrong */
63   bool (*match_fun)(void*, void*, CommImpl*) = nullptr; /* Filter function used by the other side. It is used when
64 looking if a given communication matches my needs. For that, myself must match the
65 expectations of the other side, too. See  */
66   void (*copy_data_fun)(CommImpl*, void*, size_t) = nullptr;
67
68   /* Surf action data */
69   resource::Action* src_timeout_ = nullptr; /* Surf's actions to instrument the timeouts */
70   resource::Action* dst_timeout_ = nullptr; /* Surf's actions to instrument the timeouts */
71   actor::ActorImplPtr src_actor_ = nullptr;
72   actor::ActorImplPtr dst_actor_ = nullptr;
73   s4u::Host* from_               = nullptr; /* Pre-determined only for direct host-to-host communications */
74   s4u::Host* to_                 = nullptr; /* Otherwise, computed at start() time from the actors */
75
76   /* Data to be transferred */
77   unsigned char* src_buff_ = nullptr;
78   unsigned char* dst_buff_ = nullptr;
79   size_t src_buff_size_    = 0;
80   size_t* dst_buff_size_   = nullptr;
81
82   void* src_data_ = nullptr; /* User data associated to the communication */
83   void* dst_data_ = nullptr;
84 };
85 } // namespace activity
86 } // namespace kernel
87 } // namespace simgrid
88
89 #endif