1 /* Copyright (c) 2019-2022. 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 #ifndef SIMGRID_MC_SIMCALL_COMM_OBSERVER_HPP
7 #define SIMGRID_MC_SIMCALL_COMM_OBSERVER_HPP
9 #include "simgrid/forward.h"
10 #include "src/kernel/actor/SimcallObserver.hpp"
11 #include "src/mc/transition/Transition.hpp"
12 #include "xbt/asserts.h"
20 class ActivityTestSimcall : public ResultingSimcall<bool> {
21 activity::ActivityImpl* const activity_;
24 ActivityTestSimcall(ActorImpl* actor, activity::ActivityImpl* activity)
25 : ResultingSimcall(actor, true), activity_(activity)
28 bool is_visible() const override { return true; }
29 activity::ActivityImpl* get_activity() const { return activity_; }
30 void serialize(std::stringstream& stream) const override;
33 class ActivityTestanySimcall : public ResultingSimcall<ssize_t> {
34 const std::vector<activity::ActivityImpl*>& activities_;
35 std::vector<int> indexes_; // indexes in activities_ pointing to ready activities (=whose test() is positive)
39 ActivityTestanySimcall(ActorImpl* actor, const std::vector<activity::ActivityImpl*>& activities);
40 bool is_visible() const override { return true; }
41 bool is_enabled() override { return true; /* can return -1 if no activity is ready */ }
42 void serialize(std::stringstream& stream) const override;
43 int get_max_consider() override;
44 void prepare(int times_considered) override;
45 const std::vector<activity::ActivityImpl*>& get_activities() const { return activities_; }
46 int get_value() const { return next_value_; }
49 class ActivityWaitSimcall : public ResultingSimcall<bool> {
50 activity::ActivityImpl* activity_;
51 const double timeout_;
54 ActivityWaitSimcall(ActorImpl* actor, activity::ActivityImpl* activity, double timeout)
55 : ResultingSimcall(actor, false), activity_(activity), timeout_(timeout)
58 void serialize(std::stringstream& stream) const override;
59 bool is_visible() const override { return true; }
60 bool is_enabled() override;
61 activity::ActivityImpl* get_activity() const { return activity_; }
62 void set_activity(activity::ActivityImpl* activity) { activity_ = activity; }
63 double get_timeout() const { return timeout_; }
66 class ActivityWaitanySimcall : public ResultingSimcall<ssize_t> {
67 const std::vector<activity::ActivityImpl*>& activities_;
68 std::vector<int> indexes_; // indexes in activities_ pointing to ready activities (=whose test() is positive)
69 const double timeout_;
73 ActivityWaitanySimcall(ActorImpl* actor, const std::vector<activity::ActivityImpl*>& activities, double timeout);
74 bool is_enabled() override;
75 void serialize(std::stringstream& stream) const override;
76 bool is_visible() const override { return true; }
77 void prepare(int times_considered) override;
78 int get_max_consider() override;
79 const std::vector<activity::ActivityImpl*>& get_activities() const { return activities_; }
80 double get_timeout() const { return timeout_; }
81 int get_value() const { return next_value_; }
84 class CommIsendSimcall : public SimcallObserver {
85 activity::MailboxImpl* mbox_;
88 unsigned char* src_buff_;
89 size_t src_buff_size_;
92 activity::CommImpl* comm_;
95 std::function<bool(void*, void*, activity::CommImpl*)> match_fun_;
96 std::function<void(void*)> clean_fun_; // used to free the synchro in case of problem after a detached send
97 std::function<void(activity::CommImpl*, void*, size_t)> copy_data_fun_; // used to copy data if not default one
101 ActorImpl* actor, activity::MailboxImpl* mbox, double payload_size, double rate, unsigned char* src_buff,
102 size_t src_buff_size, const std::function<bool(void*, void*, activity::CommImpl*)>& match_fun,
103 const std::function<void(void*)>& clean_fun, // used to free the synchro in case of problem after a detached send
104 const std::function<void(activity::CommImpl*, void*, size_t)>&
105 copy_data_fun, // used to copy data if not default one
106 void* payload, bool detached)
107 : SimcallObserver(actor)
109 , payload_size_(payload_size)
111 , src_buff_(src_buff)
112 , src_buff_size_(src_buff_size)
114 , detached_(detached)
115 , match_fun_(match_fun)
116 , clean_fun_(clean_fun)
117 , copy_data_fun_(copy_data_fun)
120 void serialize(std::stringstream& stream) const override;
121 bool is_visible() const override { return true; }
122 activity::MailboxImpl* get_mailbox() const { return mbox_; }
123 double get_payload_size() const { return payload_size_; }
124 double get_rate() const { return rate_; }
125 unsigned char* get_src_buff() const { return src_buff_; }
126 size_t get_src_buff_size() const { return src_buff_size_; }
127 void* get_payload() const { return payload_; }
128 bool is_detached() const { return detached_; }
129 void set_comm(activity::CommImpl* comm) { comm_ = comm; }
130 void set_tag(int tag) { tag_ = tag; }
132 auto const& get_match_fun() const { return match_fun_; }
133 auto const& get_clean_fun() const { return clean_fun_; }
134 auto const& get_copy_data_fun() const { return copy_data_fun_; }
137 class CommIrecvSimcall : public SimcallObserver {
138 activity::MailboxImpl* mbox_;
139 unsigned char* dst_buff_;
140 size_t* dst_buff_size_;
144 activity::CommImpl* comm_;
146 std::function<bool(void*, void*, activity::CommImpl*)> match_fun_;
147 std::function<void(activity::CommImpl*, void*, size_t)> copy_data_fun_; // used to copy data if not default one
150 CommIrecvSimcall(ActorImpl* actor, activity::MailboxImpl* mbox, unsigned char* dst_buff, size_t* dst_buff_size,
151 const std::function<bool(void*, void*, activity::CommImpl*)>& match_fun,
152 const std::function<void(activity::CommImpl*, void*, size_t)>& copy_data_fun, void* payload,
154 : SimcallObserver(actor)
156 , dst_buff_(dst_buff)
157 , dst_buff_size_(dst_buff_size)
160 , match_fun_(match_fun)
161 , copy_data_fun_(copy_data_fun)
164 void serialize(std::stringstream& stream) const override;
165 bool is_visible() const override { return true; }
166 activity::MailboxImpl* get_mailbox() const { return mbox_; }
167 double get_rate() const { return rate_; }
168 unsigned char* get_dst_buff() const { return dst_buff_; }
169 size_t* get_dst_buff_size() const { return dst_buff_size_; }
170 void* get_payload() const { return payload_; }
171 void set_comm(activity::CommImpl* comm) { comm_ = comm; }
172 void set_tag(int tag) { tag_ = tag; }
174 auto const& get_match_fun() const { return match_fun_; };
175 auto const& get_copy_data_fun() const { return copy_data_fun_; }
179 } // namespace kernel
180 } // namespace simgrid