-/* Copyright (c) 2009-2021. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2009-2022. 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. */
#include <typeinfo>
#include <utility>
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ker_context);
namespace simgrid {
namespace kernel {
ThreadContextFactory::ThreadContextFactory() : ContextFactory()
{
- if (smx_context_stack_size != 8 * 1024 * 1024)
+ if (stack_size != 8 * 1024 * 1024)
XBT_INFO("Stack size modifications are ignored by thread factory.");
- if (SIMIX_context_is_parallel())
+ if (is_parallel())
ParallelThreadContext::initialize();
}
ThreadContextFactory::~ThreadContextFactory()
{
- if (SIMIX_context_is_parallel())
+ if (is_parallel())
ParallelThreadContext::finalize();
}
ThreadContext* ThreadContextFactory::create_context(std::function<void()>&& code, actor::ActorImpl* actor, bool maestro)
{
- if (SIMIX_context_is_parallel())
+ if (is_parallel())
return this->new_context<ParallelThreadContext>(std::move(code), actor, maestro);
else
return this->new_context<SerialThreadContext>(std::move(code), actor, maestro);
void ThreadContextFactory::run_all()
{
- if (SIMIX_context_is_parallel()) {
+ if (is_parallel()) {
// Parallel execution
ParallelThreadContext::run_all();
} else {
// ThreadContext
ThreadContext::ThreadContext(std::function<void()>&& code, actor::ActorImpl* actor, bool maestro)
- : AttachContext(std::move(code), actor), is_maestro_(maestro)
+ : AttachContext(std::move(code), actor, maestro)
{
/* If the user provided a function for the actor then use it */
if (has_code()) {
/* create and start the actor */
this->thread_ = new std::thread(ThreadContext::wrapper, this);
- /* wait the starting of the newly created actor */
+ /* wait the start of the newly created actor */
this->end_.acquire();
}
try {
(*context)();
- if (not context->is_maestro()) { // Just in case somebody detached maestro
- context->Context::stop();
- context->stop_hook();
- }
+ if (not context->is_maestro()) // Just in case somebody detached maestro
+ context->stop();
} catch (ForcefulKillException const&) {
XBT_DEBUG("Caught a ForcefulKillException in Thread::wrapper");
xbt_assert(not context->is_maestro(), "Maestro shall not receive ForcefulKillExceptions, even when detached.");
this->end_.release();
}
-void ThreadContext::stop()
-{
- Context::stop();
- stop_hook();
- throw ForcefulKillException();
-}
-
void ThreadContext::suspend()
{
this->yield();
void ParallelThreadContext::initialize()
{
- thread_sem_ = new xbt::OsSemaphore(SIMIX_context_get_nthreads());
+ thread_sem_ = new xbt::OsSemaphore(get_nthreads());
}
void ParallelThreadContext::finalize()