Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[s4u] Move actions by the current actor in the this_actor namespace
[simgrid.git] / include / simgrid / s4u / mailbox.hpp
1 /* Copyright (c) 2006-2015. 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_S4U_MAILBOX_HPP
7 #define SIMGRID_S4U_MAILBOX_HPP
8
9 #include <xbt/base.h>
10 #include <simgrid/s4u/forward.hpp>
11
12 #ifdef __cplusplus
13
14 # include <boost/unordered_map.hpp>
15 #include <simgrid/s4u/actor.hpp>
16
17 namespace simgrid {
18 namespace s4u {
19
20 /** @brief Mailboxes
21  *
22  * Rendez-vous point for network communications, similar to URLs on which you could post and retrieve data.
23  * They are not network locations: you can post and retrieve on a given mailbox from anywhere on the network.
24  * You can access any mailbox without any latency. The network delay are only related to the location of the
25  * sender and receiver.
26  */
27 XBT_PUBLIC_CLASS Mailbox {
28   friend Comm;
29
30 private:
31   Mailbox(const char*name, smx_mailbox_t inferior);
32 public:
33   ~Mailbox();
34   
35 protected:
36   smx_mailbox_t getInferior() { return pimpl_; }
37
38 public:
39   /** Get the name of that mailbox */
40   const char *getName();
41   /** Retrieve the mailbox associated to the given string */
42   static Mailbox *byName(const char *name);
43   /** Returns whether the mailbox contains queued communications */
44   bool empty();
45
46   /** Declare that the specified process is a permanent receiver on that mailbox
47    *
48    * It means that the communications sent to this mailbox will start flowing to its host even before he does a recv().
49    * This models the real behavior of TCP and MPI communications, amongst other.
50    */
51   void setReceiver(smx_process_t process);
52   /** Return the process declared as permanent receiver, or nullptr if none **/
53   smx_process_t receiver();
54
55 private:
56   std::string name_;
57   smx_mailbox_t pimpl_;
58   static boost::unordered_map<std::string, Mailbox *> *mailboxes;
59   friend s4u::Engine;
60 };
61 }} // namespace simgrid::s4u
62
63 #endif /* C++ */
64
65 XBT_PUBLIC(sg_mbox_t) sg_mbox_by_name(const char*name);
66 XBT_PUBLIC(int) sg_mbox_is_empty(sg_mbox_t mbox);
67 XBT_PUBLIC(void)sg_mbox_setReceiver(sg_mbox_t mbox, smx_process_t process);
68 XBT_PUBLIC(smx_process_t) sg_mbox_receiver(sg_mbox_t mbox);
69
70 #endif /* SIMGRID_S4U_MAILBOX_HPP */