.. doxygenfunction:: simgrid::s4u::Mailbox::get(double timeout)
.. doxygenfunction:: simgrid::s4u::Mailbox::get_async(T **data)
.. doxygenfunction:: simgrid::s4u::Mailbox::get_init()
- .. doxygenfunction:: simgrid::s4u::Mailbox::iprobe(int type, bool(*match_fun)(void *, void *, kernel::activity::CommImpl *), void *data)
+ .. doxygenfunction:: simgrid::s4u::Mailbox::iprobe(int type, const std::function<bool(void *, void *, kernel::activity::CommImpl *)>& match_fun, void *data)
.. doxygenfunction:: simgrid::s4u::Mailbox::listen
.. doxygenfunction:: simgrid::s4u::Mailbox::ready
.. doxygenfunction:: simgrid::s4u::Comm::set_dst_data(void **buff)
.. doxygenfunction:: simgrid::s4u::Comm::set_dst_data(void **buff, size_t size)
.. doxygenfunction:: simgrid::s4u::Comm::detach()
- .. doxygenfunction:: simgrid::s4u::Comm::detach(void(*clean_function)(void *))
+ .. doxygenfunction:: simgrid::s4u::Comm::detach(const std::function<void(void*)>& clean_function)
.. doxygenfunction:: simgrid::s4u::Comm::set_payload_size(uint64_t bytes)
.. doxygenfunction:: simgrid::s4u::Comm::set_rate(double rate)
.. doxygenfunction:: simgrid::s4u::Comm::set_src_data(void *buff)
/* FIXME: expose these elements in the API */
bool detached_ = false;
- bool (*match_fun_)(void*, void*, kernel::activity::CommImpl*) = nullptr;
- void (*clean_fun_)(void*) = nullptr;
- void (*copy_data_function_)(kernel::activity::CommImpl*, void*, size_t) = nullptr;
+ std::function<bool(void*, void*, kernel::activity::CommImpl*)> match_fun_;
+ std::function<void(void*)> clean_fun_;
+ std::function<void(kernel::activity::CommImpl*, void*, size_t)> copy_data_function_;
Comm() = default;
static void on_start_cb(const std::function<void(Comm const&)>& cb) { on_start.connect(cb); }
static void on_completion_cb(const std::function<void(Activity const&)>& cb) { on_completion.connect(cb); }
/* More callbacks */
- CommPtr set_copy_data_callback(void (*callback)(kernel::activity::CommImpl*, void*, size_t));
+ CommPtr set_copy_data_callback(const std::function<void(kernel::activity::CommImpl*, void*, size_t)>& callback);
static void copy_buffer_callback(kernel::activity::CommImpl*, void*, size_t);
static void copy_pointer_callback(kernel::activity::CommImpl*, void*, size_t);
~Comm() override;
static void send(kernel::actor::ActorImpl* sender, const Mailbox* mbox, double task_size, double rate, void* src_buff,
- size_t src_buff_size, bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
- void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data,
- double timeout);
+ size_t src_buff_size,
+ const std::function<bool(void*, void*, simgrid::kernel::activity::CommImpl*)>& match_fun,
+ const std::function<void(simgrid::kernel::activity::CommImpl*, void*, size_t)>& copy_data_fun,
+ void* data, double timeout);
static void recv(kernel::actor::ActorImpl* receiver, const Mailbox* mbox, void* dst_buff, size_t* dst_buff_size,
- bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
- void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data,
- double timeout, double rate);
+ const std::function<bool(void*, void*, simgrid::kernel::activity::CommImpl*)>& match_fun,
+ const std::function<void(simgrid::kernel::activity::CommImpl*, void*, size_t)>& copy_data_fun,
+ void* data, double timeout, double rate);
/* "One-sided" communications. This way of communicating bypasses the mailbox and actors mechanism. It creates a
* communication (vetoabled, asynchronous, or synchronous) directly between two hosts. There is really no limit on
/** Start the comm, and ignore its result. It can be completely forgotten after that. */
Comm* detach();
/** Start the comm, and ignore its result. It can be completely forgotten after that. */
- Comm* detach(void (*clean_function)(void*))
+ Comm* detach(const std::function<void(void*)>& clean_function)
{
clean_fun_ = clean_function;
return detach();
static void set_config(const std::string& name, double value);
static void set_config(const std::string& name, const std::string& value);
- Engine* set_default_comm_data_copy_callback(void (*callback)(kernel::activity::CommImpl*, void*, size_t));
+ Engine*
+ set_default_comm_data_copy_callback(const std::function<void(kernel::activity::CommImpl*, void*, size_t)>& callback);
/** Add a callback fired when the platform is created (ie, the xml file parsed),
* right before the actual simulation starts. */
*/
CommPtr put_async(void* data, uint64_t simulated_size_in_bytes);
- kernel::activity::ActivityImplPtr iprobe(int type, bool (*match_fun)(void*, void*, kernel::activity::CommImpl*),
- void* data);
+ kernel::activity::ActivityImplPtr
+ iprobe(int type, const std::function<bool(void*, void*, kernel::activity::CommImpl*)>& match_fun, void* data);
/** Blocking data transmission.
*
* Please note that if you send a pointer to some data, you must ensure that your data remains live during the
xbt::signal<void(CommImpl const&)> CommImpl::on_start;
xbt::signal<void(CommImpl const&)> CommImpl::on_completion;
-void (*CommImpl::copy_data_callback_)(CommImpl*, void*, size_t) = &s4u::Comm::copy_pointer_callback;
+std::function<void(CommImpl*, void*, size_t)> CommImpl::copy_data_callback_ = &s4u::Comm::copy_pointer_callback;
-void CommImpl::set_copy_data_callback(void (*callback)(CommImpl*, void*, size_t))
+void CommImpl::set_copy_data_callback(const std::function<void(CommImpl*, void*, size_t)>& callback)
{
copy_data_callback_ = callback;
}
~CommImpl() override;
void cleanup_surf();
- static void (*copy_data_callback_)(CommImpl*, void*, size_t);
+ static std::function<void(CommImpl*, void*, size_t)> copy_data_callback_;
double rate_ = -1.0;
double size_ = 0.0;
public:
CommImpl() = default;
- static void set_copy_data_callback(void (*callback)(CommImpl*, void*, size_t));
+ static void set_copy_data_callback(const std::function<void(CommImpl*, void*, size_t)>& callback);
CommImpl& set_type(CommImplType type);
CommImplType get_type() const { return type_; }
void set_exception(actor::ActorImpl* issuer) override;
void finish() override;
- void (*clean_fun)(void*) = nullptr; /* Function to clean the detached src_buf if something goes wrong */
- bool (*match_fun)(void*, void*, CommImpl*) = nullptr; /* Filter function used by the other side. It is used when
+ std::function<void(void*)> clean_fun; /* Function to clean the detached src_buf if something goes wrong */
+ std::function<bool(void*, void*, CommImpl*)> match_fun; /* Filter function used by the other side. It is used when
looking if a given communication matches my needs. For that, myself must match the
expectations of the other side, too. See */
- void (*copy_data_fun)(CommImpl*, void*, size_t) = nullptr;
+ std::function<void(CommImpl*, void*, size_t)> copy_data_fun;
/* Surf action data */
resource::Action* src_timeout_ = nullptr; /* Surf's actions to instrument the timeouts */
}
}
-CommImplPtr MailboxImpl::iprobe(int type, bool (*match_fun)(void*, void*, CommImpl*), void* data)
+CommImplPtr MailboxImpl::iprobe(int type, const std::function<bool(void*, void*, CommImpl*)>& match_fun, void* data)
{
XBT_DEBUG("iprobe from %p %p", this, &comm_queue_);
* @param remove_matching whether or not to clean the found object from the queue
* @return The communication activity if found, nullptr otherwise
*/
-CommImplPtr MailboxImpl::find_matching_comm(CommImplType type, bool (*match_fun)(void*, void*, CommImpl*),
+CommImplPtr MailboxImpl::find_matching_comm(CommImplType type,
+ const std::function<bool(void*, void*, CommImpl*)>& match_fun,
void* this_user_data, const CommImplPtr& my_synchro, bool done,
bool remove_matching)
{
void push_done(CommImplPtr done_comm) { done_comm_queue_.push_back(done_comm); }
void remove(const CommImplPtr& comm);
void clear();
- CommImplPtr iprobe(int type, bool (*match_fun)(void*, void*, CommImpl*), void* data);
- CommImplPtr find_matching_comm(CommImplType type, bool (*match_fun)(void*, void*, CommImpl*), void* this_user_data,
- const CommImplPtr& my_synchro, bool done, bool remove_matching);
+ CommImplPtr iprobe(int type, const std::function<bool(void*, void*, CommImpl*)>& match_fun, void* data);
+ CommImplPtr find_matching_comm(CommImplType type, const std::function<bool(void*, void*, CommImpl*)>& match_fun,
+ void* this_user_data, const CommImplPtr& my_synchro, bool done, bool remove_matching);
bool is_permanent() const { return permanent_receiver_ != nullptr; }
actor::ActorImplPtr get_permanent_receiver() const { return permanent_receiver_; }
bool empty() const { return comm_queue_.empty(); }
activity::CommImpl* comm_;
int tag_;
- bool (*match_fun_)(void*, void*, activity::CommImpl*);
- void (*clean_fun_)(void*); // used to free the synchro in case of problem after a detached send
- void (*copy_data_fun_)(activity::CommImpl*, void*, size_t); // used to copy data if not default one
+ std::function<bool(void*, void*, activity::CommImpl*)> match_fun_;
+ std::function<void(void*)> clean_fun_; // used to free the synchro in case of problem after a detached send
+ std::function<void(activity::CommImpl*, void*, size_t)> copy_data_fun_; // used to copy data if not default one
public:
- CommIsendSimcall(ActorImpl* actor, activity::MailboxImpl* mbox, double payload_size, double rate,
- unsigned char* src_buff, size_t src_buff_size, bool (*match_fun)(void*, void*, activity::CommImpl*),
- void (*clean_fun)(void*), // used to free the synchro in case of problem after a detached send
- void (*copy_data_fun)(activity::CommImpl*, void*, size_t), // used to copy data if not default one
- void* payload, bool detached)
+ CommIsendSimcall(
+ ActorImpl* actor, activity::MailboxImpl* mbox, double payload_size, double rate, unsigned char* src_buff,
+ size_t src_buff_size, const std::function<bool(void*, void*, activity::CommImpl*)>& match_fun,
+ const std::function<void(void*)>& clean_fun, // used to free the synchro in case of problem after a detached send
+ const std::function<void(activity::CommImpl*, void*, size_t)>&
+ copy_data_fun, // used to copy data if not default one
+ void* payload, bool detached)
: SimcallObserver(actor)
, mbox_(mbox)
, payload_size_(payload_size)
void set_comm(activity::CommImpl* comm) { comm_ = comm; }
void set_tag(int tag) { tag_ = tag; }
- auto get_match_fun() const { return match_fun_; }
- auto get_clean_fun() const { return clean_fun_; }
- auto get_copy_data_fun() const { return copy_data_fun_; }
+ auto const& get_match_fun() const { return match_fun_; }
+ auto const& get_clean_fun() const { return clean_fun_; }
+ auto const& get_copy_data_fun() const { return copy_data_fun_; }
};
class CommIrecvSimcall : public SimcallObserver {
int tag_;
activity::CommImpl* comm_;
- bool (*match_fun_)(void*, void*, activity::CommImpl*);
- void (*copy_data_fun_)(activity::CommImpl*, void*, size_t); // used to copy data if not default one
+ std::function<bool(void*, void*, activity::CommImpl*)> match_fun_;
+ std::function<void(activity::CommImpl*, void*, size_t)> copy_data_fun_; // used to copy data if not default one
public:
CommIrecvSimcall(ActorImpl* actor, activity::MailboxImpl* mbox, unsigned char* dst_buff, size_t* dst_buff_size,
- bool (*match_fun)(void*, void*, activity::CommImpl*),
- void (*copy_data_fun)(activity::CommImpl*, void*, size_t), void* payload, double rate)
+ const std::function<bool(void*, void*, activity::CommImpl*)>& match_fun,
+ const std::function<void(activity::CommImpl*, void*, size_t)>& copy_data_fun, void* payload,
+ double rate)
: SimcallObserver(actor)
, mbox_(mbox)
, dst_buff_(dst_buff)
void set_comm(activity::CommImpl* comm) { comm_ = comm; }
void set_tag(int tag) { tag_ = tag; }
- auto get_match_fun() const { return match_fun_; };
- auto get_copy_data_fun() const { return copy_data_fun_; }
+ auto const& get_match_fun() const { return match_fun_; };
+ auto const& get_copy_data_fun() const { return copy_data_fun_; }
};
} // namespace actor
xbt::signal<void(Comm const&)> Comm::on_recv;
xbt::signal<void(Comm const&)> Comm::on_completion;
-CommPtr Comm::set_copy_data_callback(void (*callback)(kernel::activity::CommImpl*, void*, size_t))
+CommPtr Comm::set_copy_data_callback(const std::function<void(kernel::activity::CommImpl*, void*, size_t)>& callback)
{
copy_data_function_ = callback;
return this;
}
void Comm::send(kernel::actor::ActorImpl* sender, const Mailbox* mbox, double task_size, double rate, void* src_buff,
- size_t src_buff_size, bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
- void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data, double timeout)
+ size_t src_buff_size,
+ const std::function<bool(void*, void*, simgrid::kernel::activity::CommImpl*)>& match_fun,
+ const std::function<void(simgrid::kernel::activity::CommImpl*, void*, size_t)>& copy_data_fun,
+ void* data, double timeout)
{
/* checking for infinite values */
xbt_assert(std::isfinite(task_size), "task_size is not finite!");
}
void Comm::recv(kernel::actor::ActorImpl* receiver, const Mailbox* mbox, void* dst_buff, size_t* dst_buff_size,
- bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
- void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data, double timeout,
- double rate)
+ const std::function<bool(void*, void*, simgrid::kernel::activity::CommImpl*)>& match_fun,
+ const std::function<void(simgrid::kernel::activity::CommImpl*, void*, size_t)>& copy_data_fun,
+ void* data, double timeout, double rate)
{
xbt_assert(std::isfinite(timeout), "timeout is not finite!");
xbt_assert(mbox, "No rendez-vous point defined for recv");
config::set_value(name.c_str(), value);
}
-Engine* Engine::set_default_comm_data_copy_callback(void (*callback)(kernel::activity::CommImpl*, void*, size_t))
+Engine* Engine::set_default_comm_data_copy_callback(
+ const std::function<void(kernel::activity::CommImpl*, void*, size_t)>& callback)
{
kernel::activity::CommImpl::set_copy_data_callback(callback);
return this;
}
kernel::activity::ActivityImplPtr
-Mailbox::iprobe(int type, bool (*match_fun)(void*, void*, kernel::activity::CommImpl*), void* data)
+Mailbox::iprobe(int type, const std::function<bool(void*, void*, kernel::activity::CommImpl*)>& match_fun, void* data)
{
return kernel::actor::simcall_answered(
- [this, type, match_fun, data] { return pimpl_->iprobe(type, match_fun, data); });
+ [this, type, &match_fun, data] { return pimpl_->iprobe(type, match_fun, data); });
}
} // namespace s4u
} // namespace simgrid