Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill a parameter that was always nullptr
[simgrid.git] / src / kernel / context / ContextThread.cpp
index 7cb10dd..c6901c9 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2009-2023. 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 {
-namespace context {
+namespace simgrid::kernel::context {
 
 // ThreadContextFactory
 
 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()
+void ThreadContextFactory::run_all(std::vector<actor::ActorImpl*> const& actors_list)
 {
-  if (SIMIX_context_is_parallel()) {
-    // Parallel execution
-    ParallelThreadContext::run_all();
-  } else {
-    // Serial execution
-    SerialThreadContext::run_all();
-  }
+  if (is_parallel())
+    ParallelThreadContext::run_all(actors_list);
+
+  else
+    SerialThreadContext::run_all(actors_list);
 }
 
 // ThreadContext
 
 ThreadContext::ThreadContext(std::function<void()>&& code, actor::ActorImpl* actor, bool maestro)
-    : AttachContext(std::move(code), actor), is_maestro_(maestro)
+    : AttachContext(std::move(code), actormaestro)
 {
   /* 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();
   }
 
@@ -88,19 +84,15 @@ void ThreadContext::wrapper(ThreadContext* context)
 {
   Context::set_current(context);
 
-#ifndef WIN32
-  install_sigsegv_stack(nullptr, true);
-#endif
+  install_sigsegv_stack(true);
   // Tell the caller (normally the maestro) we are starting, and wait for its green light
   context->end_.release();
   context->start();
 
   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.");
@@ -111,9 +103,7 @@ void ThreadContext::wrapper(ThreadContext* context)
   // Signal to the caller (normally the maestro) that we have finished:
   context->yield();
 
-#ifndef WIN32
-  install_sigsegv_stack(nullptr, false);
-#endif
+  install_sigsegv_stack(false);
   XBT_DEBUG("Terminating");
   Context::set_current(nullptr);
 }
@@ -140,13 +130,6 @@ void ThreadContext::yield()
   this->end_.release();
 }
 
-void ThreadContext::stop()
-{
-  Context::stop();
-  stop_hook();
-  throw ForcefulKillException();
-}
-
 void ThreadContext::suspend()
 {
   this->yield();
@@ -175,10 +158,9 @@ void ThreadContext::attach_stop()
 
 // SerialThreadContext
 
-void SerialThreadContext::run_all()
+void SerialThreadContext::run_all(std::vector<actor::ActorImpl*> const& actors_list)
 {
-  const auto& to_run = EngineImpl::get_instance()->get_actors_to_run();
-  for (smx_actor_t const& actor : to_run) {
+  for (auto const* actor : actors_list) {
     XBT_DEBUG("Handling %p", actor);
     auto* context = static_cast<ThreadContext*>(actor->context_.get());
     context->release();
@@ -192,7 +174,7 @@ xbt::OsSemaphore* ParallelThreadContext::thread_sem_ = nullptr;
 
 void ParallelThreadContext::initialize()
 {
-  thread_sem_ = new xbt::OsSemaphore(SIMIX_context_get_nthreads());
+  thread_sem_ = new xbt::OsSemaphore(get_nthreads());
 }
 
 void ParallelThreadContext::finalize()
@@ -201,13 +183,12 @@ void ParallelThreadContext::finalize()
   thread_sem_ = nullptr;
 }
 
-void ParallelThreadContext::run_all()
+void ParallelThreadContext::run_all(std::vector<actor::ActorImpl*> const& actors_list)
 {
-  const auto& to_release = EngineImpl::get_instance()->get_actors_to_run();
-  for (smx_actor_t const& actor : to_release)
+  for (auto const* actor : actors_list)
     static_cast<ThreadContext*>(actor->context_.get())->release();
-  const auto& to_wait = EngineImpl::get_instance()->get_actors_to_run();
-  for (smx_actor_t const& actor : to_wait)
+
+  for (auto const* actor : actors_list)
     static_cast<ThreadContext*>(actor->context_.get())->wait();
 }
 
@@ -228,6 +209,4 @@ XBT_PRIVATE ContextFactory* thread_factory()
   XBT_VERB("Activating thread context factory");
   return new ThreadContextFactory();
 }
-} // namespace context
-} // namespace kernel
-} // namespace simgrid
+} // namespace simgrid::kernel::context