gem5  v21.1.0.2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
gem5::Fiber Class Referenceabstract

This class represents a fiber, which is a light weight sort of thread which is cooperatively scheduled and runs sequentially with other fibers, swapping in and out of a single actual thread of execution. More...

#include <fiber.hh>

Inheritance diagram for gem5::Fiber:
gem5::Coroutine< Arg, Ret > LinkedFiber sc_gem5::ScMainFiber sc_gem5::Thread::Context SwitchingFiber

Public Member Functions

virtual ~Fiber ()
 
void run ()
 Start executing the fiber represented by this object. More...
 
bool finished () const
 Returns whether the "main" function of this fiber has finished. More...
 
bool started () const
 Returns whether the "main" function of this fiber has started. More...
 
 Fiber (size_t stack_size=DefaultStackSize)
 
 Fiber (Fiber *link, size_t stack_size=DefaultStackSize)
 

Static Public Member Functions

static FibercurrentFiber ()
 Get a pointer to the current running Fiber. More...
 
static FiberprimaryFiber ()
 Get a pointer to the primary Fiber. More...
 

Static Public Attributes

const static size_t DefaultStackSize = 0x50000
 

Protected Member Functions

virtual void main ()=0
 This method is called when this fiber is first run. More...
 
void setStarted ()
 

Private Member Functions

void start ()
 
void createContext ()
 

Static Private Member Functions

static void entryTrampoline ()
 

Private Attributes

ucontext_t ctx
 
jmp_buf jmp
 
Fiberlink
 
void * stack
 
size_t stackSize
 
void * guardPage
 
size_t guardPageSize
 
bool _started
 
bool _finished
 

Detailed Description

This class represents a fiber, which is a light weight sort of thread which is cooperatively scheduled and runs sequentially with other fibers, swapping in and out of a single actual thread of execution.

To define your own threads, create a subclass of Fiber and override its main() function to do what you want your fiber to do. You can start it by calling its run() method which will stop your execution and start the other fiber in your place.

If your main() function ends, that fiber will automatically switch to either the primary fiber, or to a particular fiber you specified at construction time, and your fiber is considered finished.

Definition at line 71 of file fiber.hh.

Member Function Documentation

◆ createContext()

void gem5::Fiber::createContext ( )
private

Definition at line 123 of file fiber.cc.

References ctx, entryTrampoline(), panic_if, stack, and stackSize.

Referenced by run().

◆ entryTrampoline()

void gem5::Fiber::entryTrampoline ( )
staticprivate

Definition at line 80 of file fiber.cc.

Referenced by createContext().

◆ main()

virtual void gem5::Fiber::main ( )
protectedpure virtual

This method is called when this fiber is first run.

Override it to give your fiber something to do. When main returns, the fiber will mark itself as finished and switch to its link fiber.

Implemented in gem5::Coroutine< Arg, Ret >, sc_gem5::Thread::Context, sc_gem5::ScMainFiber, LinkedFiber, and SwitchingFiber.

Referenced by start().

◆ setStarted()

void gem5::Fiber::setStarted ( )
inlineprotected

Definition at line 142 of file fiber.hh.

References _started.

Referenced by start().

◆ start()

void gem5::Fiber::start ( )
private

Definition at line 142 of file fiber.cc.

References _finished, ctx, jmp, link, main(), panic_if, run(), and setStarted().

Member Data Documentation

◆ _finished

bool gem5::Fiber::_finished
private

Definition at line 165 of file fiber.hh.

Referenced by finished(), run(), and start().

◆ _started

bool gem5::Fiber::_started
private

Definition at line 164 of file fiber.hh.

Referenced by run(), setStarted(), and started().

◆ ctx

ucontext_t gem5::Fiber::ctx
private

Definition at line 148 of file fiber.hh.

Referenced by createContext(), and start().

◆ guardPage

void* gem5::Fiber::guardPage
private

Definition at line 158 of file fiber.hh.

Referenced by Fiber(), and ~Fiber().

◆ guardPageSize

size_t gem5::Fiber::guardPageSize
private

Definition at line 159 of file fiber.hh.

Referenced by Fiber(), and ~Fiber().

◆ jmp

jmp_buf gem5::Fiber::jmp
private

Definition at line 151 of file fiber.hh.

Referenced by run(), and start().

◆ link

Fiber* gem5::Fiber::link
private

Definition at line 153 of file fiber.hh.

Referenced by start().

◆ stack

void* gem5::Fiber::stack
private

Definition at line 156 of file fiber.hh.

Referenced by createContext(), Fiber(), and ~Fiber().

◆ stackSize

size_t gem5::Fiber::stackSize
private

Definition at line 157 of file fiber.hh.

Referenced by createContext(), and ~Fiber().


The documentation for this class was generated from the following files:

Generated on Tue Sep 21 2021 12:27:35 for gem5 by doxygen 1.8.17