Logo AND Algorithmique Numérique Distribuée

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