namespace kernel {
namespace activity {
/** @brief Returns the mailbox of that name, or nullptr */
-MailboxImpl* MailboxImpl::byNameOrNull(std::string name)
+MailboxImpl* MailboxImpl::by_name_or_null(std::string name)
{
auto mbox = mailboxes->find(name);
if (mbox != mailboxes->end())
return nullptr;
}
/** @brief Returns the mailbox of that name, newly created on need */
-MailboxImpl* MailboxImpl::byNameOrCreate(std::string name)
+MailboxImpl* MailboxImpl::by_name_or_create(std::string name)
{
/* two processes may have pushed the same mbox_create simcall at the same time */
auto m = mailboxes->find(name);
/** @brief set the receiver of the mailbox to allow eager sends
* \param actor The receiving dude
*/
-void MailboxImpl::setReceiver(s4u::ActorPtr actor)
+void MailboxImpl::set_receiver(s4u::ActorPtr actor)
{
if (actor != nullptr)
- this->permanent_receiver = actor.get()->get_impl();
+ this->permanent_receiver_ = actor->get_impl();
else
- this->permanent_receiver = nullptr;
+ this->permanent_receiver_ = nullptr;
}
/** @brief Pushes a communication activity into a mailbox
* @param comm What to add
void MailboxImpl::push(activity::CommImplPtr comm)
{
comm->mbox = this;
- this->comm_queue.push_back(std::move(comm));
+ this->comm_queue_.push_back(std::move(comm));
}
/** @brief Removes a communication activity from a mailbox
xbt_assert(comm->mbox == this, "Comm %p is in mailbox %s, not mailbox %s", comm.get(),
(comm->mbox ? comm->mbox->get_cname() : "(null)"), this->get_cname());
comm->mbox = nullptr;
- for (auto it = this->comm_queue.begin(); it != this->comm_queue.end(); it++)
+ for (auto it = this->comm_queue_.begin(); it != this->comm_queue_.end(); it++)
if (*it == comm) {
- this->comm_queue.erase(it);
+ this->comm_queue_.erase(it);
return;
}
xbt_die("Comm %p not found in mailbox %s", comm.get(), this->get_cname());
/** @brief Implementation of the simgrid::s4u::Mailbox */
class MailboxImpl {
+ friend s4u::Mailbox;
+
explicit MailboxImpl(std::string name)
- : piface_(this), name_(name), comm_queue(MAX_MAILBOX_SIZE), done_comm_queue(MAX_MAILBOX_SIZE)
+ : piface_(this), name_(name), comm_queue_(MAX_MAILBOX_SIZE), done_comm_queue_(MAX_MAILBOX_SIZE)
{
}
public:
const simgrid::xbt::string& get_name() const { return name_; }
const char* get_cname() const { return name_.c_str(); }
- static MailboxImpl* byNameOrNull(std::string name);
- static MailboxImpl* byNameOrCreate(std::string name);
- void setReceiver(s4u::ActorPtr actor);
+ static MailboxImpl* by_name_or_null(std::string name);
+ static MailboxImpl* by_name_or_create(std::string name);
+ void set_receiver(s4u::ActorPtr actor);
void push(activity::CommImplPtr comm);
void remove(smx_activity_t activity);
- simgrid::s4u::Mailbox piface_; // Our interface
+
+private:
+ simgrid::s4u::Mailbox piface_;
simgrid::xbt::string name_;
- simgrid::kernel::actor::ActorImplPtr permanent_receiver; // actor to which the mailbox is attached
- boost::circular_buffer_space_optimized<smx_activity_t> comm_queue;
- boost::circular_buffer_space_optimized<smx_activity_t> done_comm_queue; // messages already received in the permanent receive mode
+public:
+ simgrid::kernel::actor::ActorImplPtr permanent_receiver_; // actor to which the mailbox is attached
+ boost::circular_buffer_space_optimized<smx_activity_t> comm_queue_;
+ boost::circular_buffer_space_optimized<smx_activity_t>
+ done_comm_queue_; // messages already received in the permanent receive mode
};
}
}
MailboxPtr Mailbox::by_name(std::string name)
{
- kernel::activity::MailboxImpl* mbox = kernel::activity::MailboxImpl::byNameOrNull(name);
+ kernel::activity::MailboxImpl* mbox = kernel::activity::MailboxImpl::by_name_or_null(name);
if (mbox == nullptr) {
- mbox = simix::simcall([name] { return kernel::activity::MailboxImpl::byNameOrCreate(name); });
+ mbox = simix::simcall([name] { return kernel::activity::MailboxImpl::by_name_or_create(name); });
}
return MailboxPtr(&mbox->piface_, true);
}
bool Mailbox::empty()
{
- return pimpl_->comm_queue.empty();
+ return pimpl_->comm_queue_.empty();
}
bool Mailbox::listen()
{
- return not this->empty() || (pimpl_->permanent_receiver && not pimpl_->done_comm_queue.empty());
+ return not this->empty() || (pimpl_->permanent_receiver_ && not pimpl_->done_comm_queue_.empty());
}
smx_activity_t Mailbox::front()
{
- return pimpl_->comm_queue.empty() ? nullptr : pimpl_->comm_queue.front();
+ return pimpl_->comm_queue_.empty() ? nullptr : pimpl_->comm_queue_.front();
}
void Mailbox::set_receiver(ActorPtr actor)
{
- simix::simcall([this, actor]() { this->pimpl_->setReceiver(actor); });
+ simix::simcall([this, actor]() { this->pimpl_->set_receiver(actor); });
}
/** @brief get the receiver (process associated to the mailbox) */
ActorPtr Mailbox::get_receiver()
{
- if (pimpl_->permanent_receiver == nullptr)
+ if (pimpl_->permanent_receiver_ == nullptr)
return ActorPtr();
- return pimpl_->permanent_receiver->iface();
+ return pimpl_->permanent_receiver_->iface();
}
CommPtr Mailbox::put_init()
*
* If it is not found then push our communication into the rendez-vous point */
simgrid::kernel::activity::CommImplPtr other_comm =
- _find_matching_comm(&mbox->comm_queue, SIMIX_COMM_RECEIVE, match_fun, data, this_comm, /*remove_matching*/ true);
+ _find_matching_comm(&mbox->comm_queue_, SIMIX_COMM_RECEIVE, match_fun, data, this_comm, /*remove_matching*/ true);
if (not other_comm) {
other_comm = std::move(this_comm);
- if (mbox->permanent_receiver != nullptr) {
+ if (mbox->permanent_receiver_ != nullptr) {
//this mailbox is for small messages, which have to be sent right now
other_comm->state_ = SIMIX_READY;
- other_comm->dst_proc=mbox->permanent_receiver.get();
- mbox->done_comm_queue.push_back(other_comm);
+ other_comm->dst_proc = mbox->permanent_receiver_.get();
+ mbox->done_comm_queue_.push_back(other_comm);
XBT_DEBUG("pushing a message into the permanent receive list %p, comm %p", mbox, other_comm.get());
}else{
simgrid::kernel::activity::CommImplPtr other_comm;
//communication already done, get it inside the list of completed comms
- if (mbox->permanent_receiver != nullptr && not mbox->done_comm_queue.empty()) {
+ if (mbox->permanent_receiver_ != nullptr && not mbox->done_comm_queue_.empty()) {
XBT_DEBUG("We have a comm that has probably already been received, trying to match it, to skip the communication");
//find a match in the list of already received comms
- other_comm = _find_matching_comm(&mbox->done_comm_queue, SIMIX_COMM_SEND, match_fun, data, this_synchro,
+ other_comm = _find_matching_comm(&mbox->done_comm_queue_, SIMIX_COMM_SEND, match_fun, data, this_synchro,
/*remove_matching*/ true);
//if not found, assume the receiver came first, register it to the mailbox in the classical way
if (not other_comm) {
* ourself so that the other side also gets a chance of choosing if it wants to match with us.
*
* If it is not found then push our communication into the rendez-vous point */
- other_comm = _find_matching_comm(&mbox->comm_queue, SIMIX_COMM_SEND, match_fun, data, this_synchro,
+ other_comm = _find_matching_comm(&mbox->comm_queue_, SIMIX_COMM_SEND, match_fun, data, this_synchro,
/*remove_matching*/ true);
if (other_comm == nullptr) {
- XBT_DEBUG("Receive pushed first (%zu comm enqueued so far)", mbox->comm_queue.size());
+ XBT_DEBUG("Receive pushed first (%zu comm enqueued so far)", mbox->comm_queue_.size());
other_comm = std::move(this_synchro);
mbox->push(other_comm);
} else {
smx_activity_t SIMIX_comm_iprobe(smx_actor_t dst_proc, smx_mailbox_t mbox, int type, simix_match_func_t match_fun,
void* data)
{
- XBT_DEBUG("iprobe from %p %p", mbox, &mbox->comm_queue);
+ XBT_DEBUG("iprobe from %p %p", mbox, &mbox->comm_queue_);
simgrid::kernel::activity::CommImplPtr this_comm;
int smx_type;
if(type == 1){
smx_type = SIMIX_COMM_SEND;
}
smx_activity_t other_synchro=nullptr;
- if (mbox->permanent_receiver != nullptr && not mbox->done_comm_queue.empty()) {
+ if (mbox->permanent_receiver_ != nullptr && not mbox->done_comm_queue_.empty()) {
XBT_DEBUG("first check in the permanent recv mailbox, to see if we already got something");
- other_synchro = _find_matching_comm(&mbox->done_comm_queue,
- (e_smx_comm_type_t) smx_type, match_fun, data, this_comm,/*remove_matching*/false);
+ other_synchro = _find_matching_comm(&mbox->done_comm_queue_, (e_smx_comm_type_t)smx_type, match_fun, data,
+ this_comm, /*remove_matching*/ false);
}
if (not other_synchro) {
XBT_DEBUG("check if we have more luck in the normal mailbox");
- other_synchro = _find_matching_comm(&mbox->comm_queue,
- (e_smx_comm_type_t) smx_type, match_fun, data, this_comm,/*remove_matching*/false);
+ other_synchro = _find_matching_comm(&mbox->comm_queue_, (e_smx_comm_type_t)smx_type, match_fun, data, this_comm,
+ /*remove_matching*/ false);
}
return other_synchro;