diff options
Diffstat (limited to 'src/fiber.h')
-rw-r--r-- | src/fiber.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/fiber.h b/src/fiber.h new file mode 100644 index 0000000..6afc57d --- /dev/null +++ b/src/fiber.h @@ -0,0 +1,48 @@ +#ifndef INCLUDE_FIBER_H +#define INCLUDE_FIBER_H + +class Fiber +{ +public: + enum Status + { + NotStarted, + Running, + Stopped, + Terminated + }; + +public: + explicit Fiber(int stackSize = 32768); + virtual ~Fiber(); + + bool cont(); + static void yield(); + + static Fiber *currentFiber(); + + Status status() + { return _status; } + +protected: + // could be abstract if subclassing for start fiber + virtual void run() {} + +private: + // for the original fiber + Fiber(bool); + + static void yieldHelper(Status stopStatus); + + void *_stackData; + void *_stackPointer; + Fiber *_previousFiber; + Status _status; + + // should be thread local + static Fiber *_currentFiber; + + static void entryPoint(); +}; + +#endif // INCLUDE_FIBER_H |