Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
63a3f82f9a964ff35d6ae888c84382788ff2ede9
[simgrid.git] / src / kernel / context / ContextRaw.hpp
1 /* Copyright (c) 2009-2023. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef SIMGRID_KERNEL_CONTEXT_RAW_CONTEXT_HPP
7 #define SIMGRID_KERNEL_CONTEXT_RAW_CONTEXT_HPP
8
9 #include <atomic>
10 #include <cstdint>
11 #include <functional>
12 #include <vector>
13
14 #include <xbt/parmap.hpp>
15
16 #include "src/kernel/context/ContextSwapped.hpp"
17
18 namespace simgrid::kernel::context {
19
20 /** @brief Fast context switching inspired from SystemV ucontexts.
21   *
22   * The main difference to the System V context is that Raw Contexts are much faster because they don't
23   * preserve the signal mask when switching. This saves a system call (at least on Linux) on each context switch.
24   */
25 class RawContext : public SwappedContext {
26 public:
27   RawContext(std::function<void()>&& code, actor::ActorImpl* actor, SwappedContextFactory* factory);
28
29 private:
30   /** pointer to top the stack stack */
31   void* stack_top_ = nullptr;
32
33   void swap_into_for_real(SwappedContext* to) override;
34 };
35
36 class RawContextFactory : public SwappedContextFactory {
37 public:
38   RawContext* create_context(std::function<void()>&& code, actor::ActorImpl* actor) override;
39 };
40 } // namespace simgrid::kernel::context
41
42 #endif