1 /* Copyright (c) 2007-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_KERNEL_ACTIVITY_MAILBOX_HPP
7 #define SIMGRID_KERNEL_ACTIVITY_MAILBOX_HPP
9 #include "simgrid/config.h" /* FIXME: KILLME. This makes the ABI config-dependent, but mandatory for the hack below */
10 #include "simgrid/s4u/Engine.hpp"
11 #include "simgrid/s4u/Mailbox.hpp"
12 #include "src/kernel/activity/CommImpl.hpp"
13 #include "src/kernel/actor/ActorImpl.hpp"
15 namespace simgrid::kernel::activity {
17 /** @brief Implementation of the s4u::Mailbox */
22 actor::ActorImplPtr permanent_receiver_; // actor to which the mailbox is attached
23 #if SIMGRID_HAVE_STATEFUL_MC
24 /* Using deque here is faster in benchmarks, but break the state equality heuristic of Liveness checking on Debian
25 * testing. This would desserve a proper investiguation, but simply use a single-sided list for the time being. HACK.
27 std::list<CommImplPtr> comm_queue_;
28 // messages already received in the permanent receive mode
29 std::list<CommImplPtr> done_comm_queue_;
31 std::deque<CommImplPtr> comm_queue_;
32 // messages already received in the permanent receive mode
33 std::deque<CommImplPtr> done_comm_queue_;
38 friend s4u::Mailbox* s4u::Engine::mailbox_by_name_or_create(const std::string& name) const;
39 friend s4u::Mailbox* s4u::Mailbox::by_name(const std::string& name);
41 static unsigned next_id_; // Next ID to be given
42 const unsigned id_ = next_id_++;
43 explicit MailboxImpl(const std::string& name) : piface_(this), name_(name) {}
44 MailboxImpl(const MailboxImpl&) = delete;
45 MailboxImpl& operator=(const MailboxImpl&) = delete;
48 /** @brief Public interface */
49 unsigned get_id() const { return id_; }
53 const s4u::Mailbox* get_iface() const { return &piface_; }
54 s4u::Mailbox* get_iface() { return &piface_; }
56 const std::string& get_name() const { return name_; }
57 const char* get_cname() const { return name_.c_str(); }
58 void set_receiver(s4u::ActorPtr actor);
59 void push(const CommImplPtr& comm);
60 void push_done(const CommImplPtr& done_comm) { done_comm_queue_.push_back(done_comm); }
61 void remove(const CommImplPtr& comm);
62 void clear(bool do_finish);
63 CommImplPtr iprobe(int type, const std::function<bool(void*, void*, CommImpl*)>& match_fun, void* data);
64 CommImplPtr find_matching_comm(CommImplType type, const std::function<bool(void*, void*, CommImpl*)>& match_fun,
65 void* this_user_data, const CommImplPtr& my_synchro, bool done, bool remove_matching);
66 bool is_permanent() const { return permanent_receiver_ != nullptr; }
67 actor::ActorImplPtr get_permanent_receiver() const { return permanent_receiver_; }
68 bool empty() const { return comm_queue_.empty(); }
69 size_t size() const { return comm_queue_.size(); }
70 const CommImplPtr& front() const { return comm_queue_.front(); }
71 bool has_some_done_comm() const { return not done_comm_queue_.empty(); }
72 const CommImplPtr& done_front() const { return done_comm_queue_.front(); }
74 } // namespace simgrid::kernel::activity