using Ptr = boost::intrusive_ptr<Actor>;
// ***** Actor creation *****
+ /** Retrieve a reference to myself */
+ static Ptr self();
/** Create an actor using a function
*
* It means that the communications sent to this mailbox will start flowing to its host even before he does a recv().
* This models the real behavior of TCP and MPI communications, amongst other.
*/
- void setReceiver(Actor* process);
+ void setReceiver(ActorPtr process);
/** Return the process declared as permanent receiver, or nullptr if none **/
ActorPtr receiver();
#include "simgrid/msg.h"
#include "msg_private.h"
+#include "simgrid/s4u/Actor.hpp"
#include "simgrid/s4u/mailbox.hpp"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_mailbox, msg, "Logging specific to MSG (mailbox)");
*/
void MSG_mailbox_set_async(const char *alias){
simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName(alias);
-
- simcall_mbox_set_receiver(mailbox->getImpl(), SIMIX_process_self());
+ mailbox->setReceiver(simgrid::s4u::Actor::self());
XBT_VERB("%s mailbox set to receive eagerly for myself\n",alias);
}
namespace s4u {
// ***** Actor creation *****
+ActorPtr Actor::self()
+{
+ smx_context_t self_context = SIMIX_context_self();
+ if (self_context == nullptr)
+ return simgrid::s4u::ActorPtr();
+
+ return simgrid::s4u::ActorPtr(&self_context->process()->actor());
+}
+
ActorPtr Actor::createActor(const char* name, s4u::Host *host, double killTime, std::function<void()> code)
{
return pimpl_->comm_queue.empty() ? nullptr : pimpl_->comm_queue.front();
}
-void Mailbox::setReceiver(Actor* actor) {
+void Mailbox::setReceiver(ActorPtr actor) {
simcall_mbox_set_receiver(pimpl_, actor == nullptr ? nullptr : actor->pimpl_);
}
/** @brief get the receiver (process associated to the mailbox) */
ActorPtr Mailbox::receiver() {
- if(pimpl_->permanent_receiver == nullptr) return ActorPtr();
+ if(pimpl_->permanent_receiver == nullptr)
+ return ActorPtr();
return ActorPtr(&pimpl_->permanent_receiver->actor());
}