libcommunism
Userspace cooperative threading library
|
Abstract interface for a platform implementation of cothreads. More...
#include <CothreadImpl.h>
Public Types | |
using | Entry = Cothread::Entry |
Public Member Functions | |
CothreadImpl (const Cothread::Entry &entry, const size_t stackSize=0) | |
CothreadImpl (const Cothread::Entry &entry, std::span< uintptr_t > stack) | |
CothreadImpl (std::span< uintptr_t > stack) | |
virtual | ~CothreadImpl ()=default |
virtual void | switchTo (CothreadImpl *from)=0 |
virtual size_t | getStackSize () const |
virtual void * | getStack () const |
Protected Attributes | |
std::span< uintptr_t > | stack |
Stack used by this cothread, if any. More... | |
Abstract interface for a platform implementation of cothreads.
Each platform implementation derives from this base class, meaning that the cothread API that we expose to callers is just a thin shim over an instance of this class. The concrete instances of this class will end up holding the actual state of the cothread.
Definition at line 18 of file CothreadImpl.h.
Definition at line 19 of file CothreadImpl.h.
|
inline |
Initialize a cothread that begins execution at the given entry point, allocating a stack for it.
entry | Method to execute on entry to this cothread |
stackSize | Size of the stack to be allocated, in bytes. it should be a multiple of the machine word size, or specify zero to use the platform default. |
Definition at line 29 of file CothreadImpl.h.
|
inline |
Initialize the implementation to start execution at the given point with an already allocated stack.
entry | Method to execute on entry to this cothread |
stack | Buffer to use as the stack of the cothread |
Definition at line 43 of file CothreadImpl.h.
|
inline |
Create a "skeleton" cothread that has only an associated stack.
stack | Buffer to use as the stack of the cothread |
Definition at line 52 of file CothreadImpl.h.
|
virtualdefault |
Clean up all resources associated with the cothread, such as its stack.
|
inlinevirtual |
Get the top (regardless of the direction the stack grows, that is, the first byte allocated to the stack) of the stack.
Definition at line 82 of file CothreadImpl.h.
|
inlinevirtual |
Get the stack size of this cothread
Definition at line 72 of file CothreadImpl.h.
|
pure virtual |
Perform a context switch to this cothread.
The currently executing cothread's state is saved to its buffer, then this cothread's state is restored.
Implemented in libcommunism::internal::x86, libcommunism::internal::UContext, libcommunism::internal::SetJmp, libcommunism::internal::Amd64, and libcommunism::internal::Aarch64.
|
protected |
Stack used by this cothread, if any.
Definition at line 88 of file CothreadImpl.h.