33 #include <valgrind/valgrind.h> 40 #if defined(__APPLE__) && defined(__MACH__) 41 #define _DARWIN_C_SOURCE 63 class PrimaryFiber :
public Fiber 66 PrimaryFiber() :
Fiber(nullptr, 0) { setStarted(); }
67 void main() {
panic(
"PrimaryFiber main executed.\n"); }
70 PrimaryFiber _primaryFiber;
73 Fiber *_currentFiber = &_primaryFiber;
76 Fiber *startingFiber =
nullptr;
83 startingFiber->start();
95 PROT_READ | PROT_WRITE,
96 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
99 fatal(
"Could not mmap %d byte fiber stack.\n", stack_size);
104 fatal(
"Could not forbid access to fiber stack guard page.");
108 valgrindStackId = VALGRIND_STACK_REGISTER(
115 panic_if(
stack && _currentFiber ==
this,
"Fiber stack is in use.");
117 VALGRIND_STACK_DEREGISTER(valgrindStackId);
130 ctx.uc_link =
nullptr;
135 startingFiber =
this;
136 panic_if(!_currentFiber,
"No active Fiber object.");
137 swapcontext(&_currentFiber->ctx, &
ctx);
146 startingFiber =
nullptr;
153 panic_if(ret == -1, strerror(errno));
170 if (_currentFiber ==
this)
177 Fiber *prev = _currentFiber;
179 _currentFiber = next;
180 swapcontext(&prev->
ctx, &next->
ctx);
#define panic(...)
This implements a cprintf based panic() function.
void run()
Start executing the fiber represented by this object.
#define fatal(...)
This implements a cprintf based fatal() function.
Overload hash function for BasicBlockRange type.
static void entryTrampoline()
static Fiber * primaryFiber()
Get a pointer to the primary Fiber.
int main(int argc, char **argv)
This class represents a fiber, which is a light weight sort of thread which is cooperatively schedule...
Fiber(size_t stack_size=DefaultStackSize)
stack_size is the size of the stack available to this fiber.
static Fiber * currentFiber()
Get a pointer to the current running Fiber.
virtual void main()=0
This method is called when this fiber is first run.
static const int NumArgumentRegs M5_VAR_USED
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...