Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mv ActorImpl where it belongs
[simgrid.git] / src / kernel / activity / MailboxImpl.hpp
1 /* Copyright (c) 2007-2019. 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 SIMIX_MAILBOXIMPL_H
7 #define SIMIX_MAILBOXIMPL_H
8
9 #include <boost/circular_buffer.hpp>
10 #include <xbt/string.hpp>
11
12 #include "simgrid/s4u/Mailbox.hpp"
13 #include "src/kernel/activity/CommImpl.hpp"
14 #include "src/kernel/actor/ActorImpl.hpp"
15
16 namespace simgrid {
17 namespace kernel {
18 namespace activity {
19
20 /** @brief Implementation of the simgrid::s4u::Mailbox */
21
22 class MailboxImpl {
23   static constexpr size_t MAX_MAILBOX_SIZE = 10000000;
24
25   friend s4u::Mailbox;
26   friend s4u::MailboxPtr s4u::Mailbox::by_name(const std::string& name);
27   friend mc::CommunicationDeterminismChecker;
28
29   explicit MailboxImpl(const std::string& name)
30       : piface_(this), name_(name), comm_queue_(MAX_MAILBOX_SIZE), done_comm_queue_(MAX_MAILBOX_SIZE)
31   {
32   }
33
34 public:
35   const simgrid::xbt::string& get_name() const { return name_; }
36   const char* get_cname() const { return name_.c_str(); }
37   static MailboxImpl* by_name_or_null(const std::string& name);
38   static MailboxImpl* by_name_or_create(const std::string& name);
39   void set_receiver(s4u::ActorPtr actor);
40   void push(CommImplPtr comm);
41   void remove(const CommImplPtr& comm);
42   CommImplPtr iprobe(int type, int (*match_fun)(void*, void*, CommImpl*), void* data);
43   CommImplPtr find_matching_comm(CommImpl::Type type, int (*match_fun)(void*, void*, CommImpl*), void* this_user_data,
44                                  const CommImplPtr& my_synchro, bool done, bool remove_matching);
45
46 private:
47   simgrid::s4u::Mailbox piface_;
48   simgrid::xbt::string name_;
49
50 public:
51   simgrid::kernel::actor::ActorImplPtr permanent_receiver_; // actor to which the mailbox is attached
52   boost::circular_buffer_space_optimized<CommImplPtr> comm_queue_;
53   boost::circular_buffer_space_optimized<CommImplPtr> done_comm_queue_; // messages already received in the permanent
54                                                                         // receive mode
55 };
56 }
57 }
58 }
59
60 XBT_PRIVATE void SIMIX_mailbox_exit();
61
62 #endif /* SIMIX_MAILBOXIMPL_H */