Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add detached isend to maestro to allow tracking in case of fault
[simgrid.git] / src / kernel / activity / MailboxImpl.hpp
1 /* Copyright (c) 2007-2022. 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_MAILBOX_HPP
7 #define SIMGRID_KERNEL_ACTIVITY_MAILBOX_HPP
8
9 #include <boost/circular_buffer.hpp>
10 #include <xbt/string.hpp>
11
12 #include "simgrid/s4u/Engine.hpp"
13 #include "simgrid/s4u/Mailbox.hpp"
14 #include "src/kernel/activity/CommImpl.hpp"
15 #include "src/kernel/actor/ActorImpl.hpp"
16
17 namespace simgrid::kernel::activity {
18
19 /** @brief Implementation of the s4u::Mailbox */
20
21 class MailboxImpl {
22   static constexpr size_t MAX_MAILBOX_SIZE = 10000000;
23
24   s4u::Mailbox piface_;
25   xbt::string name_;
26   actor::ActorImplPtr permanent_receiver_; // actor to which the mailbox is attached
27   boost::circular_buffer_space_optimized<CommImplPtr> comm_queue_{MAX_MAILBOX_SIZE};
28   // messages already received in the permanent receive mode
29   boost::circular_buffer_space_optimized<CommImplPtr> done_comm_queue_{MAX_MAILBOX_SIZE};
30
31   friend s4u::Engine;
32   friend s4u::Mailbox;
33   friend s4u::Mailbox* s4u::Engine::mailbox_by_name_or_create(const std::string& name) const;
34   friend s4u::Mailbox* s4u::Mailbox::by_name(const std::string& name);
35
36   static unsigned next_id_; // Next ID to be given
37   const unsigned id_ = next_id_++;
38   explicit MailboxImpl(const std::string& name) : piface_(this), name_(name) {}
39   MailboxImpl(const MailboxImpl&) = delete;
40   MailboxImpl& operator=(const MailboxImpl&) = delete;
41
42 public:
43   /** @brief Public interface */
44   unsigned get_id() const { return id_; }
45
46   ~MailboxImpl();
47
48   const s4u::Mailbox* get_iface() const { return &piface_; }
49   s4u::Mailbox* get_iface() { return &piface_; }
50
51   const xbt::string& get_name() const { return name_; }
52   const char* get_cname() const { return name_.c_str(); }
53   void set_receiver(s4u::ActorPtr actor);
54   void push(CommImplPtr comm);
55   void push_done(CommImplPtr done_comm) { done_comm_queue_.push_back(done_comm); }
56   void remove(const CommImplPtr& comm);
57   void clear();
58   CommImplPtr iprobe(int type, const std::function<bool(void*, void*, CommImpl*)>& match_fun, void* data);
59   CommImplPtr find_matching_comm(CommImplType type, const std::function<bool(void*, void*, CommImpl*)>& match_fun,
60                                  void* this_user_data, const CommImplPtr& my_synchro, bool done, bool remove_matching);
61   bool is_permanent() const { return permanent_receiver_ != nullptr; }
62   actor::ActorImplPtr get_permanent_receiver() const { return permanent_receiver_; }
63   bool empty() const { return comm_queue_.empty(); }
64   size_t size() const { return comm_queue_.size(); }
65   CommImplPtr front() const { return comm_queue_.front(); }
66   bool has_some_done_comm() const { return not done_comm_queue_.empty(); }
67   CommImplPtr done_front() const { return done_comm_queue_.front(); }
68 };
69 } // namespace simgrid::kernel::activity
70
71 #endif