YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
fiber_base.cpp
Go to the documentation of this file.
2
3#include <cstdio>
4#include <utility>
5
6namespace yaclib::detail::fiber {
7
9
11
13}
14
18
20 if (_state == Completed) {
21 return;
22 }
23
24 _state = Running;
25
26 _caller_context.SwitchTo(_context);
27
28 if (_exception != nullptr) {
30 }
31}
32
34 _state = Suspended;
35 _context.SwitchTo(_caller_context);
36}
37
40}
41
43 _state = Completed;
44 if (_joining_fiber != nullptr && _thread_alive) {
45 ScheduleFiber(_joining_fiber);
46 }
47 _context.Exit(_caller_context);
48}
49
51 return _state;
52}
53
55 _joining_fiber = joining_fiber;
56}
57
59 _thread_alive = false;
60}
61
63 return _thread_alive;
64}
65
66void* FiberBase::GetTLS(std::uint64_t id, std::unordered_map<std::uint64_t, void*>& defaults) {
67 auto it = _tls.find(id);
68 if (it == _tls.end()) {
69 return defaults[id];
70 }
71 return it->second;
72}
73
74void FiberBase::SetTLS(std::uint64_t id, void* value) {
75 _tls[id] = value;
76}
77
81
83 _state = state;
84}
85
86} // namespace yaclib::detail::fiber
void SwitchTo(ExecutionContext &other)
void SetState(FiberState state) noexcept
FiberState GetState() noexcept
bool IsThreadAlive() const noexcept
void SetJoiningFiber(FiberBase *joining_fiber) noexcept
void SetTLS(std::uint64_t id, void *value)
static IStackAllocator & GetAllocator() noexcept
void * GetTLS(std::uint64_t id, std::unordered_map< std::uint64_t, void * > &defaults)
Passed to coroutine/fiber constructor, specifies the way in which memory for Stack is Allocated and R...
static DefaultAllocator sAllocator
void ScheduleFiber(FiberBase *fiber)
static FiberBase::Id sNextId
Definition fiber_base.cpp:8
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25