1 #ifndef ARCH_UCONTEXT_UCONTEXT_H
2 #define ARCH_UCONTEXT_UCONTEXT_H
11 #include <unordered_map>
68 return reinterpret_cast<ucontext_t *
>(
static_cast<UContext *
>(thread)->
stack.data());
71 static void AllocMainCothread();
73 static void EntryStub(
int id);
74 static void InvokeCothreadDidReturnHandler(Cothread *from);
114 static thread_local std::array<uintptr_t, kMainStackSize> gMainStack;
124 static std::unordered_map<int, std::unique_ptr<Context>> gContextInfo;
130 static std::mutex gContextInfoLock;
135 static int gContextNextId;
139 bool ownsStack{
false};
std::function< void()> Entry
Type alias for an entry point of a cothread.
Implementation of context switching that uses the C library's setcontext() methods.
UContext(const Entry &entry, const size_t stackSize=0)
static constexpr const size_t kStackAlignment
void switchTo(CothreadImpl *from) override
UContext(std::span< uintptr_t > stack)
static constexpr const size_t kDefaultStackSize
static constexpr const size_t kMainStackSize
Implementation details (including architecture/platform specific code) for the library.
CothreadImpl * AllocKernelThreadWrapper()
Abstract interface for a platform implementation of cothreads.
CothreadImpl(const Cothread::Entry &entry, const size_t stackSize=0)
std::span< uintptr_t > stack
Stack used by this cothread, if any.