Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
More ints converted as boolean
[simgrid.git] / src / kernel / context / ContextRaw.hpp
1 /* Copyright (c) 2009-2019. 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_SIMIX_RAW_CONTEXT_HPP
7 #define SIMGRID_SIMIX_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 {
19 namespace kernel {
20 namespace context {
21
22 /** @brief Fast context switching inspired from SystemV ucontexts.
23   *
24   * The main difference to the System V context is that Raw Contexts are much faster because they don't
25   * preserve the signal mask when switching. This saves a system call (at least on Linux) on each context switch.
26   */
27 class RawContext : public SwappedContext {
28 public:
29   RawContext(std::function<void()> code, void_pfn_smxprocess_t cleanup_func, smx_actor_t process,
30              SwappedContextFactory* factory);
31
32   void swap_into(SwappedContext* to) override;
33
34 private:
35   /** pointer to top the stack stack */
36   void* stack_top_ = nullptr;
37
38 #if HAVE_SANITIZER_ADDRESS_FIBER_SUPPORT
39   const void* asan_stack_ = nullptr;
40   size_t asan_stack_size_ = 0;
41   RawContext* asan_ctx_   = nullptr;
42   bool asan_stop_         = false;
43 #endif
44
45   static void wrapper(void* arg);
46 };
47
48 class RawContextFactory : public SwappedContextFactory {
49 public:
50   RawContextFactory() : SwappedContextFactory("RawContextFactory") {}
51
52   Context* create_context(std::function<void()> code, void_pfn_smxprocess_t cleanup, smx_actor_t process) override;
53 };
54 }}} // namespace
55
56 #endif