libcommunism
Userspace cooperative threading library
CothreadImpl.h
Go to the documentation of this file.
1 #ifndef LIBCOMMUNISM_COTHREADIMPL_H
2 #define LIBCOMMUNISM_COTHREADIMPL_H
3 
5 
6 #include <cstddef>
7 #include <cstdint>
8 #include <span>
9 
10 namespace libcommunism {
18 struct CothreadImpl {
20 
29  CothreadImpl(const Cothread::Entry &entry, const size_t stackSize = 0) {
30  (void) entry, (void) stackSize;
31  }
32 
43  CothreadImpl(const Cothread::Entry &entry, std::span<uintptr_t> stack) : stack(stack) {
44  (void) entry;
45  }
46 
52  CothreadImpl(std::span<uintptr_t> stack) : stack(stack) {}
53 
57  virtual ~CothreadImpl() = default;
58 
65  virtual void switchTo(CothreadImpl *from) = 0;
66 
72  virtual size_t getStackSize() const {
73  return this->stack.size() * sizeof(uintptr_t);
74  }
75 
82  virtual void *getStack() const {
83  return this->stack.data();
84  }
85 
86  protected:
88  std::span<uintptr_t> stack;
89 };
90 
101 }
102 
103 #endif
std::function< void()> Entry
Type alias for an entry point of a cothread.
Definition: Cothread.h:27
Main namespace for the libcommunism library.
Definition: Common.h:11
CothreadImpl * AllocKernelThreadWrapper()
Definition: Common.cpp:134
Abstract interface for a platform implementation of cothreads.
Definition: CothreadImpl.h:18
CothreadImpl(const Cothread::Entry &entry, const size_t stackSize=0)
Definition: CothreadImpl.h:29
virtual void * getStack() const
Definition: CothreadImpl.h:82
virtual void switchTo(CothreadImpl *from)=0
virtual ~CothreadImpl()=default
CothreadImpl(const Cothread::Entry &entry, std::span< uintptr_t > stack)
Definition: CothreadImpl.h:43
std::span< uintptr_t > stack
Stack used by this cothread, if any.
Definition: CothreadImpl.h:88
virtual size_t getStackSize() const
Definition: CothreadImpl.h:72
CothreadImpl(std::span< uintptr_t > stack)
Definition: CothreadImpl.h:52