Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Big bang in MC: app's observers are serialized, to become transitions in checker
[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 {
18 namespace kernel {
19 namespace activity {
20
21 /** @brief Implementation of the s4u::Mailbox */
22
23 class MailboxImpl {
24   static constexpr size_t MAX_MAILBOX_SIZE = 10000000;
25
26   s4u::Mailbox piface_;
27   xbt::string name_;
28   actor::ActorImplPtr permanent_receiver_; // actor to which the mailbox is attached
29   boost::circular_buffer_space_optimized<CommImplPtr> comm_queue_{MAX_MAILBOX_SIZE};
30   // messages already received in the permanent receive mode
31   boost::circular_buffer_space_optimized<CommImplPtr> done_comm_queue_{MAX_MAILBOX_SIZE};
32
33   friend s4u::Engine;
34   friend s4u::Mailbox;
35   friend s4u::Mailbox* s4u::Engine::mailbox_by_name_or_create(const std::string& name) const;
36   friend s4u::Mailbox* s4u::Mailbox::by_name(const std::string& name);
37   friend mc::CommunicationDeterminismChecker;
38
39   static unsigned next_id_; // Next ID to be given
40   unsigned id_;
41   explicit MailboxImpl(const std::string& name) : piface_(this), name_(name), id_(next_id_++) {}
42
43 public:
44   /** @brief Public interface */
45   unsigned get_id() { return id_; }
46
47   const s4u::Mailbox* get_iface() const { return &piface_; }
48   s4u::Mailbox* get_iface() { return &piface_; }
49
50   const xbt::string& get_name() const { return name_; }
51   const char* get_cname() const { return name_.c_str(); }
52   void set_receiver(s4u::ActorPtr actor);
53   void push(CommImplPtr comm);
54   void push_done(CommImplPtr done_comm) { done_comm_queue_.push_back(done_comm); }
55   void remove(const CommImplPtr& comm);
56   CommImplPtr iprobe(int type, bool (*match_fun)(void*, void*, CommImpl*), void* data);
57   CommImplPtr find_matching_comm(CommImpl::Type type, bool (*match_fun)(void*, void*, CommImpl*), void* this_user_data,
58                                  const CommImplPtr& my_synchro, bool done, bool remove_matching);
59   bool is_permanent() const { return permanent_receiver_ != nullptr; }
60   actor::ActorImplPtr get_permanent_receiver() const { return permanent_receiver_; }
61   bool empty() const { return comm_queue_.empty(); }
62   size_t size() const { return comm_queue_.size(); }
63   CommImplPtr front() const { return comm_queue_.front(); }
64   bool has_some_done_comm() const { return not done_comm_queue_.empty(); }
65   CommImplPtr done_front() const { return done_comm_queue_.front(); }
66 };
67 } // namespace activity
68 } // namespace kernel
69 } // namespace simgrid
70
71 #endif