{
Parmap<T>& parmap = data->parmap;
unsigned round = 0;
- kernel::context::Context* context = simix_global->context_factory->create_context(std::function<void()>(), nullptr);
+ kernel::context::Context* context =
+ simix_global->get_context_factory()->create_context(std::function<void()>(), nullptr);
kernel::context::Context::set_current(context);
XBT_CDEBUG(xbt_parmap, "New worker thread created");
*/
void EngineImpl::run_all_actors()
{
- simix_global->context_factory->run_all();
+ simix_global->get_context_factory()->run_all();
actors_to_run_.swap(actors_that_ran_);
actors_to_run_.clear();
XBT_VERB("Create context %s", actor->get_cname());
xbt_assert(simix_global != nullptr, "simix is not initialized, please call MSG_init first");
- actor->context_.reset(simix_global->context_factory->attach(actor));
+ actor->context_.reset(simix_global->get_context_factory()->attach(actor));
/* Add the actor to it's host actor list */
host->get_impl()->add_actor(actor);
this->code_ = code;
XBT_VERB("Create context %s", get_cname());
- context_.reset(simix_global->context_factory->create_context(ActorCode(code), this));
+ context_.reset(simix_global->get_context_factory()->create_context(ActorCode(code), this));
XBT_DEBUG("Start context '%s'", get_cname());
auto* maestro = new ActorImpl(xbt::string(""), /*host*/ nullptr);
if (not code) {
- maestro->context_.reset(simix_global->context_factory->create_context(ActorCode(), maestro));
+ maestro->context_.reset(simix_global->get_context_factory()->create_context(ActorCode(), maestro));
} else {
- maestro->context_.reset(simix_global->context_factory->create_maestro(ActorCode(code), maestro));
+ maestro->context_.reset(simix_global->get_context_factory()->create_maestro(ActorCode(code), maestro));
}
maestro->simcall_.issuer_ = maestro;
} // namespace simgrid
XBT_PRIVATE void SIMIX_context_mod_init();
-XBT_PRIVATE void SIMIX_context_mod_exit();
#endif
*/
void SIMIX_context_mod_init()
{
- xbt_assert(simix_global->context_factory == nullptr);
+ xbt_assert(not simix_global->has_context_factory());
#if HAVE_SMPI && (defined(__APPLE__) || defined(__NetBSD__))
smpi_init_options();
/* select the context factory to use to create the contexts */
if (simgrid::kernel::context::factory_initializer != nullptr) { // Give Java a chance to hijack the factory mechanism
- simix_global->context_factory = simgrid::kernel::context::factory_initializer();
+ simix_global->set_context_factory(simgrid::kernel::context::factory_initializer());
return;
}
/* use the factory specified by --cfg=contexts/factory:value */
for (auto const& factory : context_factories)
if (context_factory_name == factory.first) {
- simix_global->context_factory = factory.second();
+ simix_global->set_context_factory(factory.second());
break;
}
- if (simix_global->context_factory == nullptr) {
+ if (not simix_global->has_context_factory()) {
XBT_ERROR("Invalid context factory specified. Valid factories on this machine:");
#if HAVE_RAW_CONTEXTS
XBT_ERROR(" raw: high performance context factory implemented specifically for SimGrid");
}
}
-/**
- * This function is called by SIMIX_clean() to finalize the context module.
- */
-void SIMIX_context_mod_exit()
-{
- delete simix_global->context_factory;
- simix_global->context_factory = nullptr;
-}
-
/** @brief Returns whether some parallel threads are used for the user contexts. */
int SIMIX_context_is_parallel() {
return smx_parallel_contexts > 1;
simix_global->maestro_ = nullptr;
/* Finish context module and SURF */
- SIMIX_context_mod_exit();
+ simix_global->destroy_context_factory();
surf_exit();
namespace simix {
class Global {
-public:
+ kernel::context::ContextFactory* context_factory_ = nullptr;
- kernel::context::ContextFactory* context_factory = nullptr;
+public:
kernel::actor::ActorImpl* maestro_ = nullptr;
-
+ kernel::context::ContextFactory* get_context_factory() const { return context_factory_; }
+ void set_context_factory(kernel::context::ContextFactory* factory) { context_factory_ = factory; }
+ bool has_context_factory() const { return context_factory_ != nullptr; }
+ void destroy_context_factory()
+ {
+ delete context_factory_;
+ context_factory_ = nullptr;
+ }
};
}
}