1 /* Copyright (c) 2006-2015. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_S4U_MAILBOX_HPP
7 #define SIMGRID_S4U_MAILBOX_HPP
13 #include <simgrid/s4u/forward.hpp>
14 #include <simgrid/s4u/Actor.hpp>
21 * Rendez-vous point for network communications, similar to URLs on which you could post and retrieve data.
22 * They are not network locations: you can post and retrieve on a given mailbox from anywhere on the network.
23 * You can access any mailbox without any latency. The network delay are only related to the location of the
24 * sender and receiver.
26 XBT_PUBLIC_CLASS Mailbox {
28 friend simgrid::s4u::Engine;
29 friend simgrid::simix::Mailbox;
31 simgrid::simix::Mailbox *pimpl_;
33 Mailbox(smx_mailbox_t mbox): pimpl_(mbox) {}
35 // We don't have to manage the lifetime of mailboxes:
36 friend void intrusive_ptr_add_ref(Mailbox*) {}
37 friend void intrusive_ptr_release(Mailbox*) {}
39 smx_mailbox_t getImpl() { return pimpl_; } // FIXME: make me protected
42 /** Get the name of that mailbox */
43 const char *getName();
45 /** Retrieve the mailbox associated to the given string (as a C string) */
46 static MailboxPtr byName(const char *name);
48 /** Retrieve the mailbox associated to the given string (as a C++ string) */
49 static MailboxPtr byName(std::string name);
51 /** Returns whether the mailbox contains queued communications */
54 /** Returns the first element in the queue, or nullptr if none is there */
55 smx_activity_t front();
57 /** Declare that the specified process is a permanent receiver on that mailbox
59 * It means that the communications sent to this mailbox will start flowing to
60 * its host even before he does a recv(). This models the real behavior of TCP
61 * and MPI communications, amongst other.
63 void setReceiver(ActorPtr process);
65 /** Return the process declared as permanent receiver, or nullptr if none **/
69 }} // namespace simgrid::s4u
71 #endif /* SIMGRID_S4U_MAILBOX_HPP */