Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Declare variables and allocate memory when needed (plug a memory leak).
[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   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 = 0, RECEIVE, READY, DONE };
30
31   CommImpl& set_type(CommImpl::Type type);
32   CommImpl& set_size(double size);
33   CommImpl& set_src_buff(unsigned char* buff, size_t size);
34   CommImpl& set_dst_buff(unsigned char* buff, size_t* size);
35   CommImpl& set_rate(double rate);
36   CommImpl& set_mailbox(MailboxImpl* mbox);
37   CommImpl& detach();
38
39   double get_rate() const { return rate_; }
40   MailboxImpl* get_mailbox() const { return mbox_; }
41   bool detached() const { return detached_; }
42
43   void copy_data();
44
45   CommImpl* start();
46   void suspend() override;
47   void resume() override;
48   void cancel() override;
49   void post() override;
50   void finish() override;
51
52   CommImpl::Type type_;        /* Type of the communication (SIMIX_COMM_SEND or SIMIX_COMM_RECEIVE) */
53
54 #if SIMGRID_HAVE_MC
55   MailboxImpl* mbox_cpy = nullptr; /* Copy of the rendez-vous where the comm is queued, MC needs it for DPOR
56                                      (comm.mbox set to nullptr when the communication is removed from the mailbox
57                                      (used as garbage collector)) */
58 #endif
59
60   void (*clean_fun)(void*) = nullptr; /* Function to clean the detached src_buf if something goes wrong */
61   int (*match_fun)(void*, void*, CommImpl*) = nullptr; /* Filter function used by the other side. It is used when
62 looking if a given communication matches my needs. For that, myself must match the
63 expectations of the other side, too. See  */
64   void (*copy_data_fun)(CommImpl*, void*, size_t) = nullptr;
65
66   /* Surf action data */
67   resource::Action* src_timeout_ = nullptr; /* Surf's actions to instrument the timeouts */
68   resource::Action* dst_timeout_ = nullptr; /* Surf's actions to instrument the timeouts */
69   actor::ActorImplPtr src_actor_ = nullptr;
70   actor::ActorImplPtr dst_actor_ = nullptr;
71
72   /* Data to be transferred */
73   unsigned char* src_buff_ = nullptr;
74   unsigned char* dst_buff_ = nullptr;
75   size_t src_buff_size_    = 0;
76   size_t* dst_buff_size_   = nullptr;
77
78   void* src_data_ = nullptr; /* User data associated to the communication */
79   void* dst_data_ = nullptr;
80 };
81 } // namespace activity
82 } // namespace kernel
83 } // namespace simgrid
84
85 #endif