1 /* Copyright (c) 2019-2023. 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"
16 namespace simgrid::kernel::actor {
18 class ActivityTestSimcall final : public ResultingSimcall<bool> {
19 activity::ActivityImpl* const activity_;
20 std::string fun_call_;
23 ActivityTestSimcall(ActorImpl* actor, activity::ActivityImpl* activity, std::string fun_call = "")
24 : ResultingSimcall(actor, true), activity_(activity), fun_call_(fun_call)
27 activity::ActivityImpl* get_activity() const { return activity_; }
28 void serialize(std::stringstream& stream) const override;
29 std::string to_string() const override;
32 class ActivityTestanySimcall final : public ResultingSimcall<ssize_t> {
33 const std::vector<activity::ActivityImpl*>& activities_;
34 std::vector<int> indexes_; // indexes in activities_ pointing to ready activities (=whose test() is positive)
36 std::string fun_call_;
39 ActivityTestanySimcall(ActorImpl* actor, const std::vector<activity::ActivityImpl*>& activities,
40 std::string fun_call = "none");
41 bool is_enabled() override { return true; /* can return -1 if no activity is ready */ }
42 void serialize(std::stringstream& stream) const override;
43 std::string to_string() const override;
44 int get_max_consider() const override;
45 void prepare(int times_considered) override;
46 const std::vector<activity::ActivityImpl*>& get_activities() const { return activities_; }
47 int get_value() const { return next_value_; }
50 class ActivityWaitSimcall final : public ResultingSimcall<bool> {
51 activity::ActivityImpl* activity_;
52 const double timeout_;
53 std::string fun_call_;
56 ActivityWaitSimcall(ActorImpl* actor, activity::ActivityImpl* activity, double timeout, std::string fun_call = "none")
57 : ResultingSimcall(actor, false), activity_(activity), timeout_(timeout), fun_call_(fun_call)
60 void serialize(std::stringstream& stream) const override;
61 std::string to_string() const override;
62 bool is_enabled() override;
63 activity::ActivityImpl* get_activity() const { return activity_; }
64 void set_activity(activity::ActivityImpl* activity) { activity_ = activity; }
65 double get_timeout() const { return timeout_; }
68 class ActivityWaitanySimcall final : public ResultingSimcall<ssize_t> {
69 const std::vector<activity::ActivityImpl*>& activities_;
70 std::vector<int> indexes_; // indexes in activities_ pointing to ready activities (=whose test() is positive)
71 const double timeout_;
73 std::string fun_call_;
76 ActivityWaitanySimcall(ActorImpl* actor, const std::vector<activity::ActivityImpl*>& activities, double timeout,
77 std::string fun_call = "none");
78 bool is_enabled() override;
79 void serialize(std::stringstream& stream) const override;
80 std::string to_string() const override;
81 void prepare(int times_considered) override;
82 int get_max_consider() const override;
83 const std::vector<activity::ActivityImpl*>& get_activities() const { return activities_; }
84 double get_timeout() const { return timeout_; }
85 int get_value() const { return next_value_; }
88 class CommIsendSimcall final : public SimcallObserver {
89 activity::MailboxImpl* mbox_;
92 unsigned char* src_buff_;
93 size_t src_buff_size_;
96 activity::CommImpl* comm_ = {};
99 std::function<bool(void*, void*, activity::CommImpl*)> match_fun_;
100 std::function<void(void*)> clean_fun_; // used to free the synchro in case of problem after a detached send
101 std::function<void(activity::CommImpl*, void*, size_t)> copy_data_fun_; // used to copy data if not default one
103 std::string fun_call_;
107 ActorImpl* actor, activity::MailboxImpl* mbox, double payload_size, double rate, unsigned char* src_buff,
108 size_t src_buff_size, const std::function<bool(void*, void*, activity::CommImpl*)>& match_fun,
109 const std::function<void(void*)>& clean_fun, // used to free the synchro in case of problem after a detached send
110 const std::function<void(activity::CommImpl*, void*, size_t)>&
111 copy_data_fun, // used to copy data if not default one
112 void* payload, bool detached, std::string fun_call = "none")
113 : SimcallObserver(actor)
115 , payload_size_(payload_size)
117 , src_buff_(src_buff)
118 , src_buff_size_(src_buff_size)
120 , detached_(detached)
121 , match_fun_(match_fun)
122 , clean_fun_(clean_fun)
123 , copy_data_fun_(copy_data_fun)
124 , fun_call_(fun_call)
127 void serialize(std::stringstream& stream) const override;
128 std::string to_string() const override;
129 activity::MailboxImpl* get_mailbox() const { return mbox_; }
130 double get_payload_size() const { return payload_size_; }
131 double get_rate() const { return rate_; }
132 unsigned char* get_src_buff() const { return src_buff_; }
133 size_t get_src_buff_size() const { return src_buff_size_; }
134 void* get_payload() const { return payload_; }
135 bool is_detached() const { return detached_; }
136 void set_comm(activity::CommImpl* comm) { comm_ = comm; }
137 void set_tag(int tag) { tag_ = tag; }
139 auto const& get_match_fun() const { return match_fun_; }
140 auto const& get_clean_fun() const { return clean_fun_; }
141 auto const& get_copy_data_fun() const { return copy_data_fun_; }
144 class CommIrecvSimcall final : public SimcallObserver {
145 activity::MailboxImpl* mbox_;
146 unsigned char* dst_buff_;
147 size_t* dst_buff_size_;
150 activity::CommImpl* comm_ = {};
153 std::function<bool(void*, void*, activity::CommImpl*)> match_fun_;
154 std::function<void(activity::CommImpl*, void*, size_t)> copy_data_fun_; // used to copy data if not default one
156 std::string fun_call_;
159 CommIrecvSimcall(ActorImpl* actor, activity::MailboxImpl* mbox, unsigned char* dst_buff, size_t* dst_buff_size,
160 const std::function<bool(void*, void*, activity::CommImpl*)>& match_fun,
161 const std::function<void(activity::CommImpl*, void*, size_t)>& copy_data_fun, void* payload,
162 double rate, std::string fun_call = "none")
163 : SimcallObserver(actor)
165 , dst_buff_(dst_buff)
166 , dst_buff_size_(dst_buff_size)
169 , match_fun_(match_fun)
170 , copy_data_fun_(copy_data_fun)
171 , fun_call_(fun_call)
174 void serialize(std::stringstream& stream) const override;
175 std::string to_string() const override;
176 activity::MailboxImpl* get_mailbox() const { return mbox_; }
177 double get_rate() const { return rate_; }
178 unsigned char* get_dst_buff() const { return dst_buff_; }
179 size_t* get_dst_buff_size() const { return dst_buff_size_; }
180 void* get_payload() const { return payload_; }
181 void set_comm(activity::CommImpl* comm) { comm_ = comm; }
182 void set_tag(int tag) { tag_ = tag; }
184 auto const& get_match_fun() const { return match_fun_; };
185 auto const& get_copy_data_fun() const { return copy_data_fun_; }
188 } // namespace simgrid::kernel::actor