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 static thread_local Context* smx_current_context = nullptr;
26 Context* Context::self()
28 return smx_current_context;
30 void Context::set_current(Context* self)
32 smx_current_context = self;
35 void Context::declare_context(std::size_t size)
38 /* Store the address of the stack in heap to compare it apart of heap comparison */
40 MC_ignore_heap(this, size);
44 Context* ContextFactory::attach(actor::ActorImpl*)
46 xbt_die("Cannot attach with this ContextFactory.\n"
47 "Try using --cfg=contexts/factory:thread instead.\n");
50 Context* ContextFactory::create_maestro(std::function<void()>&&, actor::ActorImpl*)
52 xbt_die("Cannot create_maestro with this ContextFactory.\n"
53 "Try using --cfg=contexts/factory:thread instead.\n");
56 Context::Context(std::function<void()>&& code, actor::ActorImpl* actor) : code_(std::move(code)), actor_(actor)
58 /* If no function was provided, this is the context for maestro
59 * and we should set it as the current context */
72 this->actor_->cleanup();
75 AttachContext::~AttachContext() = default;
77 } // namespace context
79 } // namespace simgrid