YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
execution_context.cpp
Go to the documentation of this file.
1
#include <
yaclib/fault/detail/fiber/execution_context.hpp
>
2
3
#include <cstdlib>
4
5
namespace
yaclib::detail::fiber
{
6
7
void
ExecutionContext::Setup
(
Allocation
stack
,
Trampoline
trampoline
,
void
*
arg
) {
8
if
(
getcontext
(&_context) == -1) {
9
abort
();
10
}
11
_context.uc_stack.ss_sp =
stack
.start;
12
_context.uc_stack.ss_size =
stack
.size;
13
makecontext
(&_context,
reinterpret_cast<
void
(*)()
>
(
trampoline
), 1,
arg
);
14
}
15
16
void
ExecutionContext::Start
() {
17
#ifdef YACLIB_ASAN
18
__sanitizer_finish_switch_fiber
(
nullptr
,
nullptr
,
nullptr
);
19
#endif
20
}
21
22
void
ExecutionContext::SwitchTo
(
ExecutionContext
&
other
) {
23
#ifdef YACLIB_ASAN
24
void
*
fake_stack
{
nullptr
};
25
__sanitizer_start_switch_fiber
(&
fake_stack
,
other
._context.uc_stack.ss_sp,
other
._context.uc_stack.ss_size);
26
#endif
27
swapcontext
(&_context, &
other
._context);
28
#ifdef YACLIB_ASAN
29
__sanitizer_finish_switch_fiber
(
fake_stack
,
nullptr
,
nullptr
);
30
#endif
31
}
32
33
void
ExecutionContext::Exit
(
ExecutionContext
&
other
) {
34
#ifdef YACLIB_ASAN
35
__sanitizer_start_switch_fiber
(
nullptr
,
other
._context.uc_stack.ss_sp,
other
._context.uc_stack.ss_size);
36
#endif
37
setcontext
(&
other
._context);
38
}
39
40
}
// namespace yaclib::detail::fiber
yaclib::detail::fiber::ExecutionContext
Definition
execution_context.hpp:16
yaclib::detail::fiber::ExecutionContext::SwitchTo
void SwitchTo(ExecutionContext &other)
Definition
execution_context.cpp:22
yaclib::detail::fiber::ExecutionContext::Setup
void Setup(Allocation stack, Trampoline trampoline, void *arg)
Definition
execution_context.cpp:7
yaclib::detail::fiber::ExecutionContext::Exit
void Exit(ExecutionContext &other)
Definition
execution_context.cpp:33
yaclib::detail::fiber::ExecutionContext::Start
void Start()
Definition
execution_context.cpp:16
execution_context.hpp
yaclib::detail::fiber
Definition
atomic.hpp:7
yaclib::detail::fiber::Trampoline
void(*)(void *arg) Trampoline
Definition
execution_context.hpp:14
yaclib::MakeContract
Contract< V, E > MakeContract()
Creates related future and promise.
Definition
contract.hpp:25
yaclib::detail::fiber::Allocation
Definition
stack_allocator.hpp:7
src
fault
fiber
context
execution_context.cpp
Generated by
1.9.8