-/* Copyright (c) 2007-2018. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2007-2019. 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. */
ContextFactory::~ContextFactory() = default;
-Context* ContextFactory::self()
+static thread_local smx_context_t smx_current_context = nullptr;
+Context* Context::self()
{
- return SIMIX_context_get_current();
+ return smx_current_context;
+}
+void Context::set_current(Context* self)
+{
+ smx_current_context = self;
}
-void ContextFactory::declare_context(void* context, std::size_t size)
+void Context::declare_context(std::size_t size)
{
#if SIMGRID_HAVE_MC
/* Store the address of the stack in heap to compare it apart of heap comparison */
if(MC_is_active())
- MC_ignore_heap(context, size);
+ MC_ignore_heap(this, size);
#endif
}
if (has_code())
this->cleanup_func_ = cleanup_func;
else
- SIMIX_context_set_current(this);
+ 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 simix_global->context_factory->self();
- else
- return nullptr;
-}
-