Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f7a3357018cd0265485dfc96d3df31eb0483f362
[simgrid.git] / src / kernel / activity / MailboxImpl.hpp
1 /* Copyright (c) 2007-2018. 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
26   explicit MailboxImpl(std::string name)
27       : piface_(this), name_(name), comm_queue_(MAX_MAILBOX_SIZE), done_comm_queue_(MAX_MAILBOX_SIZE)
28   {
29   }
30
31 public:
32   const simgrid::xbt::string& get_name() const { return name_; }
33   const char* get_cname() const { return name_.c_str(); }
34   static MailboxImpl* by_name_or_null(std::string name);
35   static MailboxImpl* by_name_or_create(std::string name);
36   void set_receiver(s4u::ActorPtr actor);
37   void push(activity::CommImplPtr comm);
38   void remove(smx_activity_t activity);
39
40 private:
41   simgrid::s4u::Mailbox piface_;
42   simgrid::xbt::string name_;
43
44 public:
45   simgrid::kernel::actor::ActorImplPtr permanent_receiver_; // actor to which the mailbox is attached
46   boost::circular_buffer_space_optimized<smx_activity_t> comm_queue_;
47   boost::circular_buffer_space_optimized<smx_activity_t>
48       done_comm_queue_; // messages already received in the permanent receive mode
49 };
50 }
51 }
52 }
53
54 XBT_PRIVATE void SIMIX_mailbox_exit();
55
56 #endif /* SIMIX_MAILBOXIMPL_H */