jobject jprocess_from_native(msg_process_t process)
{
simgrid::kernel::context::JavaContext* context =
- (simgrid::kernel::context::JavaContext*)process->get_impl()->context_;
+ static_cast<simgrid::kernel::context::JavaContext*>(process->get_impl()->context_.get());
return context->jprocess_;
}
// - So, resume() is only launched from the parmap for the first job of each minion.
parmap_->apply(
[](smx_actor_t process) {
- SwappedContext* context = static_cast<SwappedContext*>(process->context_);
+ SwappedContext* context = static_cast<SwappedContext*>(process->context_.get());
context->resume();
},
simix_global->actors_to_run);
smx_actor_t first_actor = simix_global->actors_to_run.front();
process_index_ = 1;
/* execute the first actor; it will chain to the others when using suspend() */
- static_cast<SwappedContext*>(first_actor->context_)->resume();
+ static_cast<SwappedContext*>(first_actor->context_.get())->resume();
}
}
if (next_work) {
// There is a next soul to embody (ie, another executable actor)
XBT_DEBUG("Run next process");
- next_context = static_cast<SwappedContext*>(next_work.get()->context_);
+ next_context = static_cast<SwappedContext*>(next_work.get()->context_.get());
} else {
// All actors were run, go back to the parmap context
XBT_DEBUG("No more actors to run");
if (i < simix_global->actors_to_run.size()) {
/* Actually swap into the next actor directly without transiting to maestro */
XBT_DEBUG("Run next actor");
- next_context = static_cast<SwappedContext*>(simix_global->actors_to_run[i]->context_);
+ next_context = static_cast<SwappedContext*>(simix_global->actors_to_run[i]->context_.get());
} else {
/* all processes were run, actually return to maestro */
XBT_DEBUG("No more actors to run");
void ThreadContext::attach_start()
{
// We're breaking the layers here by depending on the upper layer:
- ThreadContext* maestro = (ThreadContext*)simix_global->maestro_process->context_;
+ ThreadContext* maestro = static_cast<ThreadContext*>(simix_global->maestro_process->context_.get());
maestro->begin_.release();
xbt_assert(not this->is_maestro());
this->start();
xbt_assert(not this->is_maestro());
this->yield();
- ThreadContext* maestro = (ThreadContext*)simix_global->maestro_process->context_;
+ ThreadContext* maestro = static_cast<ThreadContext*>(simix_global->maestro_process->context_.get());
maestro->end_.acquire();
Context::set_current(nullptr);
{
for (smx_actor_t const& actor : simix_global->actors_to_run) {
XBT_DEBUG("Handling %p", actor);
- ThreadContext* context = static_cast<ThreadContext*>(actor->context_);
+ ThreadContext* context = static_cast<ThreadContext*>(actor->context_.get());
context->release();
context->wait();
}
void ParallelThreadContext::run_all()
{
for (smx_actor_t const& actor : simix_global->actors_to_run)
- static_cast<ThreadContext*>(actor->context_)->release();
+ static_cast<ThreadContext*>(actor->context_.get())->release();
for (smx_actor_t const& actor : simix_global->actors_to_run)
- static_cast<ThreadContext*>(actor->context_)->wait();
+ static_cast<ThreadContext*>(actor->context_.get())->wait();
}
void ParallelThreadContext::start_hook()
}
smx_context_t MSG_process_get_smx_ctx(msg_process_t process) { // deprecated -- smx_context_t should die afterward
- return process->get_impl()->context_;
+ return process->get_impl()->context_.get();
}
/** @brief Add a function to the list of "on_exit" functions for the current process.
* The on_exit functions are the functions executed when your process is killed.
simcall.issuer = this;
}
-ActorImpl::~ActorImpl()
-{
- delete this->context_;
-}
+ActorImpl::~ActorImpl() = default;
+
/* Become an actor in the simulation
*
* Currently this can only be called by the main thread (once) and only work with some thread factories
XBT_VERB("Create context %s", actor->get_cname());
xbt_assert(simix_global != nullptr, "simix is not initialized, please call MSG_init first");
- actor->context_ = simix_global->context_factory->attach(actor);
+ actor->context_.reset(simix_global->context_factory->attach(actor));
/* Add properties */
if (properties != nullptr)
simix_global->actors_to_run.push_back(actor);
intrusive_ptr_add_ref(actor);
- auto* context = dynamic_cast<simgrid::kernel::context::AttachContext*>(actor->context_);
+ auto* context = dynamic_cast<simgrid::kernel::context::AttachContext*>(actor->context_.get());
xbt_assert(nullptr != context, "Not a suitable context");
context->attach_start();
this->code = code;
XBT_VERB("Create context %s", get_cname());
- context_ = simix_global->context_factory->create_context(simix::ActorCode(code), this);
+ context_.reset(simix_global->context_factory->create_context(simix::ActorCode(code), this));
XBT_DEBUG("Start context '%s'", get_cname());
ActorImpl* maestro = new ActorImpl(xbt::string(""), /*host*/ nullptr);
if (not code) {
- maestro->context_ = simix_global->context_factory->create_context(simix::ActorCode(), maestro);
+ maestro->context_.reset(simix_global->context_factory->create_context(simix::ActorCode(), maestro));
} else {
- maestro->context_ = simix_global->context_factory->create_maestro(simix::ActorCode(code), maestro);
+ maestro->context_.reset(simix_global->context_factory->create_maestro(simix::ActorCode(code), maestro));
}
maestro->simcall.issuer = maestro;
#include <functional>
#include <list>
#include <map>
+#include <memory>
struct s_smx_process_exit_fun_t {
std::function<void(bool, void*)> fun;
bool has_to_auto_restart() { return auto_restart_; }
void set_auto_restart(bool autorestart) { auto_restart_ = autorestart; }
- context::Context* context_ = nullptr; /* the context (uctx/raw/thread) that executes the user function */
+ std::unique_ptr<context::Context> context_; /* the context (uctx/raw/thread) that executes the user function */
std::exception_ptr exception_;
bool finished_ = false;
#endif
/* Let's free maestro now */
- delete simix_global->maestro_process->context_;
- simix_global->maestro_process->context_ = nullptr;
delete simix_global->maestro_process;
simix_global->maestro_process = nullptr;