JNIEnv *get_current_thread_env()
{
using simgrid::kernel::context::JavaContext;
- JavaContext* ctx = static_cast<JavaContext*>(SIMIX_context_self());
+ JavaContext* ctx = static_cast<JavaContext*>(simgrid::kernel::context::Context::self());
return ctx->jenv_;
}
static int java_main(int argc, char *argv[])
{
JNIEnv *env = get_current_thread_env();
- simgrid::kernel::context::JavaContext* context = static_cast<simgrid::kernel::context::JavaContext*>(SIMIX_context_self());
+ simgrid::kernel::context::JavaContext* context =
+ static_cast<simgrid::kernel::context::JavaContext*>(simgrid::kernel::context::Context::self());
//Change the "." in class name for "/".
std::string arg0 = argv[0];
void java_main_jprocess(jobject jprocess)
{
JNIEnv *env = get_current_thread_env();
- simgrid::kernel::context::JavaContext* context = static_cast<simgrid::kernel::context::JavaContext*>(SIMIX_context_self());
+ simgrid::kernel::context::JavaContext* context =
+ static_cast<simgrid::kernel::context::JavaContext*>(simgrid::kernel::context::Context::self());
context->jprocess_ = jprocess;
jprocess_bind(context->jprocess_, MSG_process_self(), env);
ContextFactory::~ContextFactory() = default;
-static thread_local smx_context_t smx_current_context;
+static thread_local smx_context_t smx_current_context = nullptr;
Context* Context::self()
{
return smx_current_context;
set_current(this);
}
-Context::~Context() = default;
+Context::~Context()
+{
+ if (self() == this)
+ set_current(nullptr);
+}
void Context::stop()
{
{
simix_global->context_factory->run_all();
}
-
-/** @brief returns the current running context */
-smx_context_t SIMIX_context_self()
-{
- if (simix_global && simix_global->context_factory)
- return simgrid::kernel::context::Context::self();
- else
- return nullptr;
-}
/** @brief Executes all the processes to run (in parallel if possible). */
XBT_PRIVATE void SIMIX_context_runall();
-/** @brief returns the current running context */
-XBT_PUBLIC smx_context_t SIMIX_context_self(); // public because it's used in simgrid-java
XBT_PRIVATE void *SIMIX_context_stack_new();
XBT_PRIVATE void SIMIX_context_stack_delete(void *stack);
{
worker_id_ = threads_working_.fetch_add(1, std::memory_order_relaxed);
- ParallelBoostContext* worker_context = static_cast<ParallelBoostContext*>(SIMIX_context_self());
+ ParallelBoostContext* worker_context = static_cast<ParallelBoostContext*>(self());
workers_context_[worker_id_] = worker_context;
Context::set_current(this);
void ParallelRawContext::resume()
{
worker_id_ = threads_working_.fetch_add(1, std::memory_order_relaxed);
- ParallelRawContext* worker_context = static_cast<ParallelRawContext*>(SIMIX_context_self());
+ ParallelRawContext* worker_context = static_cast<ParallelRawContext*>(self());
workers_context_[worker_id_] = worker_context;
XBT_DEBUG("Saving worker stack %zu", worker_id_);
Context::set_current(this);
// What is my containing body? Store its number in os-thread-specific area :
worker_id_ = threads_working_.fetch_add(1, std::memory_order_relaxed);
// Get my current soul:
- ParallelUContext* worker_context = static_cast<ParallelUContext*>(SIMIX_context_self());
+ ParallelUContext* worker_context = static_cast<ParallelUContext*>(self());
// Write down that this soul is hosted in that body (for now)
workers_context_[worker_id_] = worker_context;
// Write in simix that I switched my soul
// ***** Actor creation *****
ActorPtr Actor::self()
{
- smx_context_t self_context = SIMIX_context_self();
+ smx_context_t self_context = simgrid::kernel::context::Context::self();
if (self_context == nullptr)
return simgrid::s4u::ActorPtr();
*/
smx_actor_t SIMIX_process_self()
{
- smx_context_t self_context = SIMIX_context_self();
+ smx_context_t self_context = simgrid::kernel::context::Context::self();
return (self_context != nullptr) ? self_context->process() : nullptr;
}
void SIMIX_process_detach()
{
- auto* context = dynamic_cast<simgrid::kernel::context::AttachContext*>(SIMIX_context_self());
+ auto* context = dynamic_cast<simgrid::kernel::context::AttachContext*>(simgrid::kernel::context::Context::self());
if (context == nullptr)
xbt_die("Not a suitable context");