1 /* Copyright (c) 2007-2019. 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. */
8 #include "simgrid/s4u/Host.hpp"
9 #include "src/kernel/activity/CommImpl.hpp"
10 #include "src/kernel/context/Context.hpp"
11 #include "src/simix/smx_private.hpp"
12 #include "src/surf/surf_interface.hpp"
14 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
21 ContextFactoryInitializer factory_initializer = nullptr;
23 ContextFactory::~ContextFactory() = default;
25 thread_local Context* Context::current_ = nullptr;
27 void Context::declare_context(std::size_t size)
30 /* Store the address of the stack in heap to compare it apart of heap comparison */
32 MC_ignore_heap(this, size);
36 Context* ContextFactory::attach(actor::ActorImpl*)
38 xbt_die("Cannot attach with this ContextFactory.\n"
39 "Try using --cfg=contexts/factory:thread instead.\n");
42 Context* ContextFactory::create_maestro(std::function<void()>&&, actor::ActorImpl*)
44 xbt_die("Cannot create_maestro with this ContextFactory.\n"
45 "Try using --cfg=contexts/factory:thread instead.\n");
48 Context::Context(std::function<void()>&& code, actor::ActorImpl* actor) : code_(std::move(code)), actor_(actor)
50 /* If no function was provided, this is the context for maestro
51 * and we should set it as the current context */
64 this->actor_->cleanup();
67 AttachContext::~AttachContext() = default;
69 } // namespace context
71 } // namespace simgrid
73 /** @brief Executes all the processes to run (in parallel if possible). */
74 void SIMIX_context_runall()
76 simix_global->context_factory->run_all();