- if (smx_ctx_thread_sem)
- xbt_os_sem_release(smx_ctx_thread_sem);
- xbt_os_sem_release(this->end_);
+ xbt_assert(not this->is_maestro());
+ this->yield();
+
+ auto* maestro = static_cast<ThreadContext*>(EngineImpl::get_instance()->get_maestro()->context_.get());
+ maestro->end_.acquire();
+
+ Context::set_current(nullptr);
+}
+
+// SerialThreadContext
+
+void SerialThreadContext::run_all()
+{
+ const auto& to_run = EngineImpl::get_instance()->get_actors_to_run();
+ for (smx_actor_t const& actor : to_run) {
+ XBT_DEBUG("Handling %p", actor);
+ auto* context = static_cast<ThreadContext*>(actor->context_.get());
+ context->release();
+ context->wait();
+ }
+}
+
+// ParallelThreadContext
+
+xbt::OsSemaphore* ParallelThreadContext::thread_sem_ = nullptr;
+
+void ParallelThreadContext::initialize()
+{
+ thread_sem_ = new xbt::OsSemaphore(get_nthreads());
+}
+
+void ParallelThreadContext::finalize()
+{
+ delete thread_sem_;
+ thread_sem_ = nullptr;
+}
+
+void ParallelThreadContext::run_all()
+{
+ const auto& to_release = EngineImpl::get_instance()->get_actors_to_run();
+ for (smx_actor_t const& actor : to_release)
+ 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)
+ static_cast<ThreadContext*>(actor->context_.get())->wait();
+}