-/* This function is called by maestro at the beginning of a scheduling round to get all working threads executing some stuff
- * It is much easier to understand what happens if you see the working threads as bodies that swap their soul for the
- * ones of the simulated processes that must run.
- */
-void UContextFactory::run_all()
-{
- if (sysv_parallel) {
-#if HAVE_THREAD_CONTEXTS
- sysv_threads_working = 0;
- // Parmap_apply ensures that every working thread get an index in the
- // process_to_run array (through an atomic fetch_and_add),
- // and runs the smx_ctx_sysv_resume_parallel function on that index
-
- // We lazily create the parmap because the parmap creates context
- // with simix_global->context_factory (which might not be initialized
- // when bootstrapping):
- if (sysv_parmap == nullptr)
- sysv_parmap =
- new simgrid::xbt::Parmap<smx_actor_t>(SIMIX_context_get_nthreads(), SIMIX_context_get_parallel_mode());
-
- sysv_parmap->apply(
- [](smx_actor_t process) {
- ParallelUContext* context = static_cast<ParallelUContext*>(process->context);
- context->resume();
- },
- simix_global->process_to_run);
-#else
- xbt_die("You asked for a parallel execution, but you don't have any threads.");
-#endif
- } else {
- // Serial:
- if (simix_global->process_to_run.empty())
- return;
-
- smx_actor_t first_process = simix_global->process_to_run.front();
- sysv_process_index = 1;
- SerialUContext* context = static_cast<SerialUContext*>(first_process->context);
- context->resume();
- }
-}
-
-Context* UContextFactory::create_context(std::function<void()> code,
- void_pfn_smxprocess_t cleanup, smx_actor_t process)
-{
- if (sysv_parallel)
- return new_context<ParallelUContext>(std::move(code), cleanup, process);
- else
- return new_context<SerialUContext>(std::move(code), cleanup, process);
-}
-
-UContext::UContext(std::function<void()> code,
- void_pfn_smxprocess_t cleanup_func, smx_actor_t process)
- : Context(std::move(code), cleanup_func, process)
+UContext::UContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process,
+ SwappedContextFactory* factory)
+ : SwappedContext(std::move(code), cleanup_func, process, factory)