gem5  v20.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
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 Fiber:
LinkedFiber m5::Coroutine< Arg, Ret > sc_gem5::ScMainFiber sc_gem5::Thread::Context SwitchingFiber

Public Member Functions

 Fiber (size_t stack_size=DefaultStackSize)
 stack_size is the size of the stack available to this fiber. More...
 
 Fiber (Fiber *link, size_t stack_size=DefaultStackSize)
 
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...
 

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

static const 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
 
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 62 of file fiber.hh.

Constructor & Destructor Documentation

◆ Fiber() [1/2]

Fiber::Fiber ( size_t  stack_size = DefaultStackSize)

stack_size is the size of the stack available to this fiber.

link points to another fiber which will start executing when this fiber's main function returns.

Definition at line 84 of file fiber.cc.

Referenced by TEST().

◆ Fiber() [2/2]

Fiber::Fiber ( Fiber link,
size_t  stack_size = DefaultStackSize 
)

Definition at line 87 of file fiber.cc.

References fatal, guardPage, guardPageSize, and stack.

◆ ~Fiber()

Fiber::~Fiber ( )
virtual

Definition at line 111 of file fiber.cc.

References guardPage, guardPageSize, panic_if, stack, and stackSize.

Member Function Documentation

◆ createContext()

void Fiber::createContext ( )
private

Definition at line 122 of file fiber.cc.

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

Referenced by run().

◆ currentFiber()

Fiber * Fiber::currentFiber ( )
static

Get a pointer to the current running Fiber.

Definition at line 181 of file fiber.cc.

Referenced by m5::Coroutine< Arg, Ret >::call(), and started().

◆ entryTrampoline()

void Fiber::entryTrampoline ( )
staticprivate

Definition at line 79 of file fiber.cc.

Referenced by createContext(), and setStarted().

◆ finished()

bool Fiber::finished ( ) const
inline

◆ main()

virtual void 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 m5::Coroutine< Arg, Ret >, LinkedFiber, sc_gem5::Thread::Context, SwitchingFiber, and sc_gem5::ScMainFiber.

Referenced by start(), started(), and TEST().

◆ primaryFiber()

Fiber * Fiber::primaryFiber ( )
static

Get a pointer to the primary Fiber.

This Fiber represents the thread of execution started by the OS, and which has a Fiber attached to it after the fact.

Definition at line 182 of file fiber.cc.

Referenced by sc_gem5::Process::fiber(), sc_gem5::Scheduler::start(), started(), TEST(), and sc_gem5::Scheduler::yield().

◆ run()

void Fiber::run ( )

Start executing the fiber represented by this object.

This function will "return" when the current fiber is switched back to later on.

Definition at line 163 of file fiber.cc.

References _finished, _started, createContext(), ctx, and panic_if.

Referenced by m5::Coroutine< Arg, Ret >::call(), sc_gem5::Scheduler::pause(), start(), sc_gem5::Scheduler::start(), sc_gem5::Scheduler::stop(), TEST(), sc_gem5::Scheduler::throwUp(), and sc_gem5::Scheduler::yield().

◆ setStarted()

void Fiber::setStarted ( )
inlineprotected

Definition at line 101 of file fiber.hh.

References _started, entryTrampoline(), and start().

Referenced by start().

◆ start()

void Fiber::start ( )
private

Definition at line 141 of file fiber.cc.

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

Referenced by setStarted().

◆ started()

bool Fiber::started ( ) const
inline

Returns whether the "main" function of this fiber has started.

Definition at line 85 of file fiber.hh.

References _started, currentFiber(), main(), and primaryFiber().

Referenced by TEST().

Member Data Documentation

◆ _finished

bool Fiber::_finished
private

Definition at line 120 of file fiber.hh.

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

◆ _started

bool Fiber::_started
private

Definition at line 119 of file fiber.hh.

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

◆ ctx

ucontext_t Fiber::ctx
private

Definition at line 107 of file fiber.hh.

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

◆ DefaultStackSize

const size_t Fiber::DefaultStackSize = 0x50000
static

Definition at line 65 of file fiber.hh.

Referenced by sc_gem5::Process::Process().

◆ guardPage

void* Fiber::guardPage
private

Definition at line 113 of file fiber.hh.

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

◆ guardPageSize

size_t Fiber::guardPageSize
private

Definition at line 114 of file fiber.hh.

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

◆ link

Fiber* Fiber::link
private

Definition at line 108 of file fiber.hh.

Referenced by start().

◆ stack

void* Fiber::stack
private

Definition at line 111 of file fiber.hh.

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

◆ stackSize

size_t Fiber::stackSize
private

Definition at line 112 of file fiber.hh.

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


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

Generated on Thu May 28 2020 16:21:44 for gem5 by doxygen 1.8.13