-/** A better makecontext
- *
- * Makecontext expects integer arguments, we the context variable is decomposed into a serie of integers and each
- * integer is passed as argument to makecontext.
- */
-void UContext::make_ctx(ucontext_t* ucp, void (*func)(int, int), UContext* arg)
-{
- int ctx_addr[CTX_ADDR_LEN]{};
- memcpy(ctx_addr, &arg, sizeof arg);
- makecontext(ucp, (void (*)())func, 2, ctx_addr[0], ctx_addr[1]);
-}
-
-inline void UContext::swap(UContext* from, UContext* to)
-{
- ASAN_ONLY(void* fake_stack = nullptr);
- ASAN_ONLY(to->asan_ctx_ = from);
- ASAN_START_SWITCH(from->asan_stop_ ? nullptr : &fake_stack, to->asan_stack_, to->asan_stack_size_);
- swapcontext(&from->uc_, &to->uc_);
- ASAN_FINISH_SWITCH(fake_stack, &from->asan_ctx_->asan_stack_, &from->asan_ctx_->asan_stack_size_);
-}
-
-void UContext::stop()
-{
- Context::stop();
- throw StopRequest();
-}
-
-// SerialUContext
-
-unsigned long SerialUContext::process_index_; /* index of the next process to run in the list of runnable processes */
-
-void SerialUContext::suspend()
-{
- /* determine the next context */
- SerialUContext* next_context;
- unsigned long int i = process_index_;
- process_index_++;
-
- if (i < simix_global->process_to_run.size()) {
- /* execute the next process */
- XBT_DEBUG("Run next process");
- next_context = static_cast<SerialUContext*>(simix_global->process_to_run[i]->context_);
- } else {
- /* all processes were run, return to maestro */
- XBT_DEBUG("No more process to run");
- next_context = static_cast<SerialUContext*>(UContext::getMaestro());
- }
- SIMIX_context_set_current(next_context);
- UContext::swap(this, next_context);
-}
-
-void SerialUContext::resume()
-{
- SIMIX_context_set_current(this);
- UContext::swap(UContext::getMaestro(), this);
-}