A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
simplify griffon.cpp
[simgrid.git]
/
src
/
s4u
/
s4u_Mailbox.cpp
diff --git
a/src/s4u/s4u_Mailbox.cpp
b/src/s4u/s4u_Mailbox.cpp
index d153c08080045822c4e6482c4ed63a7b02984363..76613fbfa85d3715118f10eb9414645b3a6d97cc 100644
(file)
--- a/
src/s4u/s4u_Mailbox.cpp
+++ b/
src/s4u/s4u_Mailbox.cpp
@@
-1,21
+1,20
@@
-/* Copyright (c) 2006-202
0
. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2006-202
3
. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-#include "simgrid/s4u/Comm.hpp"
-#include "simgrid/s4u/Mailbox.hpp"
-#include "src/kernel/activity/MailboxImpl.hpp"
-
#include <simgrid/mailbox.h>
#include <simgrid/mailbox.h>
+#include <simgrid/s4u/Engine.hpp>
+#include <simgrid/s4u/Mailbox.hpp>
+
+#include "src/kernel/activity/MailboxImpl.hpp"
XBT_LOG_EXTERNAL_CATEGORY(s4u);
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_channel, s4u, "S4U Communication Mailboxes");
XBT_LOG_EXTERNAL_CATEGORY(s4u);
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_channel, s4u, "S4U Communication Mailboxes");
-namespace simgrid {
-namespace s4u {
+namespace simgrid::s4u {
-const
xbt
::string& Mailbox::get_name() const
+const
std
::string& Mailbox::get_name() const
{
return pimpl_->get_name();
}
{
return pimpl_->get_name();
}
@@
-27,138
+26,127
@@
const char* Mailbox::get_cname() const
Mailbox* Mailbox::by_name(const std::string& name)
{
Mailbox* Mailbox::by_name(const std::string& name)
{
- kernel::activity::MailboxImpl* mbox = kernel::activity::MailboxImpl::by_name_or_null(name);
- if (mbox == nullptr) {
- mbox = kernel::actor::simcall([&name] { return kernel::activity::MailboxImpl::by_name_or_create(name); });
- }
- return &mbox->piface_;
+ return Engine::get_instance()->mailbox_by_name_or_create(name);
+}
+
+bool Mailbox::empty() const
+{
+ return pimpl_->empty();
}
}
-bool Mailbox::empty()
+size_t Mailbox::size() const
{
{
- return pimpl_->
comm_queue_.empty
();
+ return pimpl_->
size
();
}
}
-bool Mailbox::listen()
+bool Mailbox::listen()
const
{
{
- return not
this->empty() || (pimpl_->permanent_receiver_ && not pimpl_->done_comm_queue_.empty
());
+ return not
pimpl_->empty() || (pimpl_->is_permanent() && pimpl_->has_some_done_comm
());
}
}
-bool Mailbox::ready()
+aid_t Mailbox::listen_from() const
+{
+ kernel::activity::CommImplPtr comm = front();
+ if (comm && comm->src_actor_)
+ return comm->src_actor_->get_pid();
+ else
+ return -1;
+}
+
+bool Mailbox::ready() const
{
bool comm_ready = false;
{
bool comm_ready = false;
- if (not pimpl_->
comm_queue_.
empty()) {
- comm_ready = pimpl_->
comm_queue_.front()->state_
== kernel::activity::State::DONE;
+ if (not pimpl_->empty()) {
+ comm_ready = pimpl_->
front()->get_state()
== kernel::activity::State::DONE;
- } else if (pimpl_->
permanent_receiver_ && not pimpl_->done_comm_queue_.empty
()) {
- comm_ready = pimpl_->done_
comm_queue_.front()->state_
== kernel::activity::State::DONE;
+ } else if (pimpl_->
is_permanent() && pimpl_->has_some_done_comm
()) {
+ comm_ready = pimpl_->done_
front()->get_state()
== kernel::activity::State::DONE;
}
return comm_ready;
}
}
return comm_ready;
}
-kernel::activity::CommImplPtr Mailbox::front()
+kernel::activity::CommImplPtr Mailbox::front()
const
{
{
- return pimpl_->
comm_queue_.empty() ? nullptr : pimpl_->comm_queue_.
front();
+ return pimpl_->
empty() ? nullptr : pimpl_->
front();
}
void Mailbox::set_receiver(ActorPtr actor)
{
}
void Mailbox::set_receiver(ActorPtr actor)
{
- kernel::actor::simcall([this, actor]() { this->pimpl_->set_receiver(actor); });
+ kernel::actor::simcall
_answered
([this, actor]() { this->pimpl_->set_receiver(actor); });
}
/** @brief get the receiver (process associated to the mailbox) */
}
/** @brief get the receiver (process associated to the mailbox) */
-ActorPtr Mailbox::get_receiver()
+ActorPtr Mailbox::get_receiver()
const
{
{
- if (pimpl_->
permanent_receiver_ == nullptr
)
+ if (pimpl_->
is_permanent()
)
return ActorPtr();
return ActorPtr();
- return pimpl_->
permanent_receiver_->
iface();
+ return pimpl_->
get_permanent_receiver()->get_
iface();
}
CommPtr Mailbox::put_init()
{
}
CommPtr Mailbox::put_init()
{
- CommPtr res
= CommPtr(new s4u::
Comm());
+ CommPtr res
(new
Comm());
res->sender_ = kernel::actor::ActorImpl::self();
res->sender_ = kernel::actor::ActorImpl::self();
- res->
mailbox_ = this
;
+ res->
set_mailbox(this)
;
return res;
}
return res;
}
-s4u::CommPtr Mailbox::put_init(void* data, uint64_t simulated_size_in_bytes)
+
+CommPtr Mailbox::put_init(void* payload, uint64_t simulated_size_in_bytes)
{
{
- s4u::CommPtr res = put_init();
- res->set_remaining(simulated_size_in_bytes);
- res->src_buff_ = data;
- res->src_buff_size_ = sizeof(void*);
- return res;
+ return put_init()->set_payload_size(simulated_size_in_bytes)->set_src_data(payload)->set_src_data_size(sizeof(void*));
}
}
-s4u::CommPtr Mailbox::put_async(void* payload, uint64_t simulated_size_in_bytes)
+
+CommPtr Mailbox::put_async(void* payload, uint64_t simulated_size_in_bytes)
{
xbt_assert(payload != nullptr, "You cannot send nullptr");
{
xbt_assert(payload != nullptr, "You cannot send nullptr");
-
s4u::
CommPtr res = put_init(payload, simulated_size_in_bytes);
- res->
vetoable_
start();
+ CommPtr res = put_init(payload, simulated_size_in_bytes);
+ res->start();
return res;
}
return res;
}
+
void Mailbox::put(void* payload, uint64_t simulated_size_in_bytes)
{
xbt_assert(payload != nullptr, "You cannot send nullptr");
void Mailbox::put(void* payload, uint64_t simulated_size_in_bytes)
{
xbt_assert(payload != nullptr, "You cannot send nullptr");
- CommPtr c = put_init();
- c->set_remaining(simulated_size_in_bytes);
- c->set_src_data(payload);
- c->vetoable_start();
- c->wait();
+ put_init()->set_payload_size(simulated_size_in_bytes)->set_src_data(payload)->start()->wait();
}
}
+
/** Blocking send with timeout */
void Mailbox::put(void* payload, uint64_t simulated_size_in_bytes, double timeout)
{
xbt_assert(payload != nullptr, "You cannot send nullptr");
/** Blocking send with timeout */
void Mailbox::put(void* payload, uint64_t simulated_size_in_bytes, double timeout)
{
xbt_assert(payload != nullptr, "You cannot send nullptr");
- CommPtr c = put_init();
- c->set_remaining(simulated_size_in_bytes);
- c->set_src_data(payload);
- c->vetoable_start();
- c->wait_for(timeout);
+ put_init()->set_payload_size(simulated_size_in_bytes)->set_src_data(payload)->start()->wait_for(timeout);
}
}
-
s4u::
CommPtr Mailbox::get_init()
+CommPtr Mailbox::get_init()
{
{
-
CommPtr res = CommPtr(new s4u::Comm()
);
+
auto res = CommPtr(new Comm())->set_mailbox(this
);
res->receiver_ = kernel::actor::ActorImpl::self();
res->receiver_ = kernel::actor::ActorImpl::self();
- res->mailbox_ = this;
- return res;
-}
-s4u::CommPtr Mailbox::get_async(void** data)
-{
- s4u::CommPtr res = get_init();
- res->set_dst_data(data, sizeof(*data));
- res->vetoable_start();
return res;
}
return res;
}
-
void* Mailbox::get
()
+
CommPtr Mailbox::get_async
()
{
{
- void* res = nullptr;
- CommPtr c = get_init();
- c->set_dst_data(&res, sizeof(res));
- c->vetoable_start();
- c->wait();
+ CommPtr res = get_init()->set_dst_data(nullptr, sizeof(void*));
+ res->start();
return res;
}
return res;
}
-void* Mailbox::get(double timeout)
+
+kernel::activity::ActivityImplPtr
+Mailbox::iprobe(int type, const std::function<bool(void*, void*, kernel::activity::CommImpl*)>& match_fun, void* data)
{
{
- void* res = nullptr;
- CommPtr c = get_init();
- c->set_dst_data(&res, sizeof(res));
- c->vetoable_start();
- c->wait_for(timeout);
- return res;
+ return kernel::actor::simcall_answered(
+ [this, type, &match_fun, data] { return pimpl_->iprobe(type, match_fun, data); });
}
}
-
smx_activity_t Mailbox::iprobe(int type, bool (*match_fun)(void*, void*, kernel::activity::CommImpl*), void* data
)
+
void Mailbox::clear(
)
{
{
-
return kernel::actor::simcall([this, type, match_fun, data] { return pimpl_->iprobe(type, match_fun, data
); });
+
kernel::actor::simcall_answered([this]() { this->pimpl_->clear(true
); });
}
}
-} // namespace s4u
-} // namespace simgrid
+
+} // namespace simgrid
::s4u
/* **************************** Public C interface *************************** */
sg_mailbox_t sg_mailbox_by_name(const char* alias)
/* **************************** Public C interface *************************** */
sg_mailbox_t sg_mailbox_by_name(const char* alias)
@@
-166,7
+154,7
@@
sg_mailbox_t sg_mailbox_by_name(const char* alias)
return simgrid::s4u::Mailbox::by_name(alias);
}
return simgrid::s4u::Mailbox::by_name(alias);
}
-const char* sg_mailbox_get_name(sg_mailbox_t mailbox)
+const char* sg_mailbox_get_name(
const_
sg_mailbox_t mailbox)
{
return mailbox->get_cname();
}
{
return mailbox->get_cname();
}
@@
-197,12
+185,19
@@
int sg_mailbox_listen(const char* alias)
void* sg_mailbox_get(sg_mailbox_t mailbox)
{
void* sg_mailbox_get(sg_mailbox_t mailbox)
{
- return mailbox->get();
+ return mailbox->get<void>();
+}
+
+sg_comm_t sg_mailbox_get_async(sg_mailbox_t mailbox, void** data)
+{
+ auto comm = mailbox->get_async<void>(data);
+ comm->add_ref();
+ return comm.get();
}
void sg_mailbox_put(sg_mailbox_t mailbox, void* payload, long simulated_size_in_bytes)
{
}
void sg_mailbox_put(sg_mailbox_t mailbox, void* payload, long simulated_size_in_bytes)
{
-
return
mailbox->put(payload, simulated_size_in_bytes);
+ mailbox->put(payload, simulated_size_in_bytes);
}
sg_comm_t sg_mailbox_put_async(sg_mailbox_t mailbox, void* payload, long simulated_size_in_bytes)
}
sg_comm_t sg_mailbox_put_async(sg_mailbox_t mailbox, void* payload, long simulated_size_in_bytes)
@@
-211,3
+206,10
@@
sg_comm_t sg_mailbox_put_async(sg_mailbox_t mailbox, void* payload, long simulat
comm->add_ref();
return comm.get();
}
comm->add_ref();
return comm.get();
}
+
+sg_comm_t sg_mailbox_put_init(sg_mailbox_t mailbox, void* payload, long simulated_size_in_bytes)
+{
+ auto comm = mailbox->put_init(payload, simulated_size_in_bytes);
+ comm->add_ref();
+ return comm.get();
+}