Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f62d3266f382154849bfa6126381b86d7e6c2e76
[simgrid.git] / src / kernel / activity / MailboxImpl.hpp
1 /* Copyright (c) 2007-2017. 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
11 #include "simgrid/s4u/Mailbox.hpp"
12 #include "src/simix/ActorImpl.hpp"
13
14 #define MAX_MAILBOX_SIZE 10000000
15 namespace simgrid {
16 namespace kernel {
17 namespace activity {
18
19 /** @brief Implementation of the simgrid::s4u::Mailbox */
20
21 class MailboxImpl {
22   explicit MailboxImpl(const char* name)
23       : piface_(this), name_(xbt_strdup(name)), comm_queue(MAX_MAILBOX_SIZE), done_comm_queue(MAX_MAILBOX_SIZE)
24   {
25   }
26
27 public:
28   ~MailboxImpl() { xbt_free(name_); }
29
30   static MailboxImpl* byNameOrNull(const char* name);
31   static MailboxImpl* byNameOrCreate(const char* name);
32   void setReceiver(s4u::ActorPtr actor);
33   void push(smx_activity_t synchro);
34   void remove(smx_activity_t activity);
35   simgrid::s4u::Mailbox piface_; // Our interface
36   char* name_;
37
38   boost::intrusive_ptr<simgrid::simix::ActorImpl> permanent_receiver; // process which the mailbox is attached to
39   boost::circular_buffer_space_optimized<smx_activity_t> comm_queue;
40   boost::circular_buffer_space_optimized<smx_activity_t> done_comm_queue; // messages already received in the permanent receive mode
41 };
42 }
43 }
44 }
45
46 XBT_PRIVATE void SIMIX_mailbox_exit();
47
48 #endif /* SIMIX_MAILBOXIMPL_H */