Zth (libzth)
zth::Fiber Class Reference

The fiber. More...

#include <fiber.h>

Inheritance diagram for zth::Fiber:
zth::Listable< Fiber > zth::UniqueID< Fiber > zth::UniqueIDBase zth::TypedFiber< R, R(*)(Args...)> zth::TypedFiber< void, void(*)(Args...)> zth::TypedFiber< R, F > zth::TypedFiberN< R, Args > zth::TypedFiberN< void, Args... >

Public Types

enum  State {
  Uninitialized = 0 , New , Ready , Running ,
  Waiting , Suspended , Dead
}
 
typedef void() FiberHook(Fiber &)
 
typedef ContextAttr::EntryArg EntryArg
 
typedef void(* Entry) (EntryArg)
 
- Public Types inherited from zth::Listable< Fiber >
typedef Fiber type
 

Public Member Functions

 Fiber (Entry entry, EntryArg arg=EntryArg())
 
virtual ~Fiber () override
 
int setStackSize (size_t size) noexcept
 
size_t stackSize () const noexcept
 
size_t stackUsage () const
 
Contextcontext () const noexcept
 
State state () const noexcept
 
void * fls () const noexcept
 
void setFls (void *data=nullptr) noexcept
 
Timestamp const & runningSince () const noexcept
 
Timestamp const & stateEnd () const noexcept
 
TimeInterval const & totalTime () const noexcept
 
void addCleanup (void(*f)(Fiber &, void *), void *arg)
 
int init (Timestamp const &now=Timestamp::now())
 
int run (Fiber &from, Timestamp now=Timestamp::now())
 
bool allowYield (Timestamp const &now=Timestamp::now()) const noexcept
 
void kill () noexcept
 
void nap (Timestamp const &sleepUntil=Timestamp::null()) noexcept
 
void wakeup () noexcept
 
void suspend () noexcept
 
void resume () noexcept
 
string str () const
 
- Public Member Functions inherited from zth::Listable< Fiber >
constexpr Listable () noexcept
 
constexpr Listable (Listable const &e) noexcept
 
 Listable (Listable &&l) noexcept
 
Listableoperator= (Listable const &rhs) noexcept
 
Listableoperator= (Listable &&l) noexcept
 
typelistNext () const noexcept
 
typelistPrev () const noexcept
 
- Public Member Functions inherited from zth::UniqueID< Fiber >
 UniqueID (UniqueID const &)=delete
 
 UniqueID (UniqueID &&u) noexcept
 
 UniqueID (string const &name)
 
 UniqueID (string &&name)
 
 UniqueID (char const *name=nullptr)
 
UniqueIDoperator= (UniqueID const &)=delete
 
UniqueIDoperator= (UniqueID &&u) noexcept
 
virtual ~UniqueID ()=default
 
void const * normptr () const noexcept
 
uint64_t id () const noexcept
 
string const & name () const noexcept
 
void setName (string const &name)
 
void setName (char const *name)
 
void setName (string &&name)
 
virtual char const * id_str () const override
 

Static Public Attributes

static FiberHookhookNew = nullptr
 Hook to be called when a Fiber is created. More...
 
static FiberHookhookDead = nullptr
 Hook to be called when a Fiber is destroyed. More...
 
static uintptr_t const ExitUnknown = (uintptr_t)-1
 

Protected Member Functions

virtual void changedName (string const &name) override
 
void setState (State state, Timestamp const &t=Timestamp::now()) noexcept
 
void fiberEntry_ () noexcept
 
- Protected Member Functions inherited from zth::UniqueIDBase
virtual ~UniqueIDBase ()=default
 

Static Protected Member Functions

static void fiberEntry (void *that) noexcept
 

Additional Inherited Members

- Static Public Member Functions inherited from zth::UniqueID< Fiber >
static uint64_t getID () noexcept
 
- Public Attributes inherited from zth::Listable< Fiber >
Listableprev
 
Listableleft
 
Listablenext
 
Listableright
 

Detailed Description

The fiber.

This class manages a fiber's context and state, given an entry function.

Usually, don't subclass this class (use zth::Runnable instead), as the zth::Fiber is owned by and part of a zth::Worker's administration. For example, a Fiber object is deleted by the Worker when it is dead.

Examples
measure.cpp.

Definition at line 50 of file fiber.h.

Member Typedef Documentation

◆ Entry

typedef void(* zth::Fiber::Entry) (EntryArg)

Definition at line 74 of file fiber.h.

◆ EntryArg

Definition at line 73 of file fiber.h.

◆ FiberHook

typedef void() zth::Fiber::FiberHook(Fiber &)

Definition at line 55 of file fiber.h.

Member Enumeration Documentation

◆ State

Enumerator
Uninitialized 
New 
Ready 
Running 
Waiting 
Suspended 
Dead 

Definition at line 71 of file fiber.h.

Constructor & Destructor Documentation

◆ Fiber()

zth::Fiber::Fiber ( Entry  entry,
EntryArg  arg = EntryArg() 
)
inlineexplicit

Definition at line 77 of file fiber.h.

◆ ~Fiber()

virtual zth::Fiber::~Fiber ( )
inlineoverridevirtual

Definition at line 98 of file fiber.h.

Member Function Documentation

◆ addCleanup()

void zth::Fiber::addCleanup ( void(*)(Fiber &, void *)  f,
void *  arg 
)
inline

Definition at line 173 of file fiber.h.

◆ allowYield()

bool zth::Fiber::allowYield ( Timestamp const &  now = Timestamp::now()) const
inlinenoexcept

Definition at line 266 of file fiber.h.

◆ changedName()

virtual void zth::Fiber::changedName ( string const &  name)
inlineoverrideprotectedvirtual

Reimplemented from zth::UniqueID< Fiber >.

Definition at line 398 of file fiber.h.

◆ context()

Context* zth::Fiber::context ( ) const
inlinenoexcept
Examples
measure.cpp.

Definition at line 138 of file fiber.h.

◆ fiberEntry()

static void zth::Fiber::fiberEntry ( void *  that)
inlinestaticprotectednoexcept

Definition at line 416 of file fiber.h.

◆ fiberEntry_()

void zth::Fiber::fiberEntry_ ( )
inlineprotectednoexcept

Definition at line 423 of file fiber.h.

◆ fls()

void* zth::Fiber::fls ( ) const
inlinenoexcept

Definition at line 148 of file fiber.h.

◆ init()

int zth::Fiber::init ( Timestamp const &  now = Timestamp::now())
inline

Definition at line 178 of file fiber.h.

◆ kill()

void zth::Fiber::kill ( )
inlinenoexcept
Examples
measure.cpp.

Definition at line 271 of file fiber.h.

◆ nap()

void zth::Fiber::nap ( Timestamp const &  sleepUntil = Timestamp::null())
inlinenoexcept

Definition at line 280 of file fiber.h.

◆ resume()

void zth::Fiber::resume ( )
inlinenoexcept

Definition at line 350 of file fiber.h.

◆ run()

int zth::Fiber::run ( Fiber from,
Timestamp  now = Timestamp::now() 
)
inline

Definition at line 200 of file fiber.h.

◆ runningSince()

Timestamp const& zth::Fiber::runningSince ( ) const
inlinenoexcept

Definition at line 158 of file fiber.h.

◆ setFls()

void zth::Fiber::setFls ( void *  data = nullptr)
inlinenoexcept

Definition at line 153 of file fiber.h.

◆ setStackSize()

int zth::Fiber::setStackSize ( size_t  size)
inlinenoexcept

Definition at line 119 of file fiber.h.

◆ setState()

void zth::Fiber::setState ( State  state,
Timestamp const &  t = Timestamp::now() 
)
inlineprotectednoexcept

Definition at line 403 of file fiber.h.

◆ stackSize()

size_t zth::Fiber::stackSize ( ) const
inlinenoexcept

Definition at line 128 of file fiber.h.

◆ stackUsage()

size_t zth::Fiber::stackUsage ( ) const
inline

Definition at line 133 of file fiber.h.

◆ state()

State zth::Fiber::state ( ) const
inlinenoexcept

Definition at line 143 of file fiber.h.

◆ stateEnd()

Timestamp const& zth::Fiber::stateEnd ( ) const
inlinenoexcept

Definition at line 163 of file fiber.h.

◆ str()

string zth::Fiber::str ( ) const
inline

Definition at line 361 of file fiber.h.

◆ suspend()

void zth::Fiber::suspend ( )
inlinenoexcept

Definition at line 328 of file fiber.h.

◆ totalTime()

TimeInterval const& zth::Fiber::totalTime ( ) const
inlinenoexcept

Definition at line 168 of file fiber.h.

◆ wakeup()

void zth::Fiber::wakeup ( )
inlinenoexcept

Definition at line 310 of file fiber.h.

Member Data Documentation

◆ ExitUnknown

uintptr_t const zth::Fiber::ExitUnknown = (uintptr_t)-1
static

Definition at line 75 of file fiber.h.

◆ hookDead

Fiber::FiberHook * zth::Fiber::hookDead = nullptr
static

Hook to be called when a Fiber is destroyed.

This function is called just after the fiber has died.

Definition at line 69 of file fiber.h.

◆ hookNew

Fiber::FiberHook * zth::Fiber::hookNew = nullptr
static

Hook to be called when a Fiber is created.

This function is called after initialization of the fiber.

Definition at line 62 of file fiber.h.


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