62 static void DefaultCothreadReturnedHandler(
Cothread *);
77 thread_local
Cothread *Cothread::gCurrent{
nullptr};
84 static void libcommunism::internal::DefaultCothreadReturnedHandler(
Cothread *thread) {
85 std::cerr <<
"[libcommunism] Cothread $" << std::hex << thread << std::dec;
87 const auto &label = thread->
getLabel();
89 std::cerr <<
" (" << thread->
getLabel() <<
")";
91 std::cerr <<
" (unnamed cothread)";
95 std::cerr <<
" returned from entry point!" << std::endl;
100 this->impl = AllocImpl(this->implBuffer, this->implBufferUsed, entry, stackSize);
104 this->impl = AllocImpl(this->implBuffer, this->implBufferUsed, entry, stack);
109 if(this->implBufferUsed) {
114 this->impl =
nullptr;
121 std::cerr <<
"failed to allocate kernel cothread wrapper!" << std::endl;
139 auto from = Current()->impl;
141 this->impl->switchTo(from);
145 return this->impl->getStack();
149 return this->impl->getStackSize();
Instance of a single cooperative thread.
static void SetReturnHandler(const std::function< void(Cothread *)> &handler)
Cothread(const Entry &entry, const size_t stackSize=0)
std::function< void()> Entry
Type alias for an entry point of a cothread.
static Cothread * Current()
size_t getStackSize() const
constexpr auto & getLabel() const
static void ResetReturnHandler()
Implementation details (including architecture/platform specific code) for the library.
std::function< void(libcommunism::Cothread *)> gReturnHandler
Main namespace for the libcommunism library.
CothreadImpl * AllocKernelThreadWrapper()
Abstract interface for a platform implementation of cothreads.