Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
14a03d3882752cd793e9cadb36b064abbee482ff
[simgrid.git] / src / kernel / activity / MailboxImpl.hpp
1 /* Copyright (c) 2007-2021. 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
29   friend s4u::Engine;
30   friend s4u::Mailbox* s4u::Engine::mailbox_by_name_or_create(const std::string& name) const;
31   friend s4u::Mailbox;
32   friend s4u::Mailbox* s4u::Mailbox::by_name(const std::string& name);
33   friend mc::CommunicationDeterminismChecker;
34
35   explicit MailboxImpl(const std::string& name) : piface_(this), name_(name) {}
36
37 public:
38   /** @brief Public interface */
39   const s4u::Mailbox* get_iface() const { return &piface_; }
40   s4u::Mailbox* get_iface() { return &piface_; }
41
42   const xbt::string& get_name() const { return name_; }
43   const char* get_cname() const { return name_.c_str(); }
44   void set_receiver(s4u::ActorPtr actor);
45   void push(CommImplPtr comm);
46   void remove(const CommImplPtr& comm);
47   CommImplPtr iprobe(int type, bool (*match_fun)(void*, void*, CommImpl*), void* data);
48   CommImplPtr find_matching_comm(CommImpl::Type type, bool (*match_fun)(void*, void*, CommImpl*), void* this_user_data,
49                                  const CommImplPtr& my_synchro, bool done, bool remove_matching);
50
51   actor::ActorImplPtr permanent_receiver_; // actor to which the mailbox is attached
52   boost::circular_buffer_space_optimized<CommImplPtr> comm_queue_{MAX_MAILBOX_SIZE};
53   // messages already received in the permanent receive mode
54   boost::circular_buffer_space_optimized<CommImplPtr> done_comm_queue_{MAX_MAILBOX_SIZE};
55 };
56 } // namespace activity
57 } // namespace kernel
58 } // namespace simgrid
59
60 #endif