Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move MailboxImpl to kernel::activity where it belongs
[simgrid.git] / src / s4u / s4u_mailbox.cpp
1 /* Copyright (c) 2006-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "xbt/log.h"
8 #include "src/msg/msg_private.h"
9 #include "src/simix/ActorImpl.hpp"
10 #include "src/simix/smx_network_private.h"
11 #include "simgrid/s4u/Mailbox.hpp"
12
13 XBT_LOG_EXTERNAL_CATEGORY(s4u);
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_channel,s4u,"S4U Communication Mailboxes");
15
16 namespace simgrid {
17 namespace s4u {
18
19 const char *Mailbox::name() {
20   return pimpl_->name_;
21 }
22
23 MailboxPtr Mailbox::byName(const char*name)
24 {
25   kernel::activity::MailboxImpl* mbox = kernel::activity::MailboxImpl::byNameOrNull(name);
26   if (mbox == nullptr) {
27     mbox = simix::kernelImmediate([name] {
28       return kernel::activity::MailboxImpl::byNameOrCreate(name);
29     });
30   }
31   return MailboxPtr(&mbox->piface_, true);
32 }
33
34 MailboxPtr Mailbox::byName(std::string name)
35 {
36   return byName(name.c_str());
37 }
38
39 bool Mailbox::empty()
40 {
41   return pimpl_->comm_queue.empty();
42 }
43
44 smx_activity_t Mailbox::front()
45 {
46   return pimpl_->comm_queue.empty() ? nullptr : pimpl_->comm_queue.front();
47 }
48
49 void Mailbox::setReceiver(ActorPtr actor) {
50   simix::kernelImmediate([this, actor]() {
51     this->pimpl_->setReceiver(actor);
52   });
53 }
54
55 /** @brief get the receiver (process associated to the mailbox) */
56 ActorPtr Mailbox::receiver() {
57   if(pimpl_->permanent_receiver == nullptr)
58     return ActorPtr();
59   return ActorPtr(&pimpl_->permanent_receiver->getIface());
60 }
61
62 }
63 }