1 /* Copyright (c) 2009-2018. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "src/kernel/context/context_private.hpp"
7 #include "src/simix/ActorImpl.hpp"
8 #include "src/simix/smx_private.hpp"
10 #include "ContextSwapped.hpp"
12 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
18 unsigned long SwappedContext::process_index_;
20 SwappedContext* SwappedContext::maestro_context_ = nullptr;
22 void SwappedContext::suspend()
24 /* determine the next context */
25 SwappedContext* next_context;
26 unsigned long int i = process_index_;
29 if (i < simix_global->process_to_run.size()) {
30 /* execute the next process */
31 XBT_DEBUG("Run next process");
32 next_context = static_cast<SwappedContext*>(simix_global->process_to_run[i]->context_);
34 /* all processes were run, return to maestro */
35 XBT_DEBUG("No more process to run");
36 next_context = static_cast<SwappedContext*>(get_maestro());
38 Context::set_current(next_context);
39 this->swap_into(next_context);
42 void SwappedContext::resume()
44 SwappedContext* old = static_cast<SwappedContext*>(self());
45 Context::set_current(this);
49 void SwappedContext::run_all()
51 if (simix_global->process_to_run.empty())
53 smx_actor_t first_process = simix_global->process_to_run.front();
55 /* execute the first process */
56 static_cast<SwappedContext*>(first_process->context_)->resume();
58 } // namespace context
60 } // namespace simgrid