Zth (libzth)
Loading...
Searching...
No Matches
zth::TypedFiber< R > Class Template Referenceabstract

Typed fiber class. More...

#include <async.h>

Inheritance diagram for zth::TypedFiber< R >:
zth::Fiber zth::Listable zth::UniqueID< Fiber > zth::RefCounted zth::NamedUniqueID< Named > zth::UniqueIDBase zth::TypedFiberN< F, R, Args >

Public Types

typedef R Return
 
typedef Future< ReturnFuture_type
 
- Public Types inherited from zth::Fiber
enum  State {
  Uninitialized = 0 , New , Ready , Running ,
  Waiting , Suspended , Dead
}
 
typedef void() FiberHook(Fiber &)
 
typedef ContextAttr::EntryArg EntryArg
 
typedef void(* Entry) (EntryArg)
 
typedef Hook< Fiber & > Hook_type
 
- Public Types inherited from zth::Listable
typedef void * user_type
 
- Public Types inherited from zth::UniqueID< Fiber >
typedef NamedUniqueID base
 

Public Member Functions

constexpr TypedFiber ()
 
virtual ~TypedFiber () noexcept override=default
 
void registerFuture (Future_type *future)
 
Future_typefuture () const
 
SharedPointer< Future_type > const & withFuture ()
 
 operator SharedPointer< Future_type > const & ()
 
 operator SharedReference< Future_type > ()
 
- Public Member Functions inherited from zth::Fiber
 Fiber (Entry entry, EntryArg arg=EntryArg())
 
virtual ~Fiber () noexcept 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 atExit (Hook_type::function_type f, Hook_type::arg_type arg=Hook_type::arg_type())
 
void atCleanup (Hook_type::function_type f, Hook_type::arg_type arg=Hook_type::arg_type())
 
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
constexpr Listable () noexcept
 
constexpr Listable (Listable const &e) noexcept
 
Listableoperator= (Listable const &rhs) noexcept
 
 Listable (Listable &&l) noexcept
 
Listableoperator= (Listable &&l) 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 () noexcept override=default
 
void const * normptr () const noexcept
 
uint64_t id () const noexcept
 
- Public Member Functions inherited from zth::NamedUniqueID< Named >
virtual ~NamedUniqueID () noexcept override=default
 
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 noexcept override
 
- Public Member Functions inherited from zth::RefCounted
 RefCounted () noexcept
 
virtual ~RefCounted () noexcept
 
void used () noexcept
 
bool unused () noexcept
 
size_t refs () const noexcept
 

Protected Member Functions

virtual void entry_ ()=0
 
template<typename T >
void setFuture (T const &r)
 
void setFuture ()
 
- Protected Member Functions inherited from zth::Fiber
void setState (State state, Timestamp const &t=Timestamp::now()) noexcept
 
void fiberEntry_ () noexcept
 
- Protected Member Functions inherited from zth::UniqueID< Fiber >
virtual uint64_t id_ () const noexcept final
 
- Protected Member Functions inherited from zth::NamedUniqueID< Named >
 NamedUniqueID (char const *name=nullptr)
 
 NamedUniqueID (string const &name)
 
 NamedUniqueID (string &&name)
 
- Protected Member Functions inherited from zth::UniqueIDBase
virtual ~UniqueIDBase () noexcept=default
 
- Protected Member Functions inherited from zth::RefCounted
virtual void cleanup () noexcept
 

Static Protected Member Functions

static void entry (void *that)
 
- Static Protected Member Functions inherited from zth::Fiber
static void fiberEntry (void *that) noexcept
 

Additional Inherited Members

- Static Public Member Functions inherited from zth::UniqueID< Fiber >
static uint64_t getID () noexcept
 
- Static Public Attributes inherited from zth::Fiber
static FiberHookhookNew = nullptr
 Hook to be called when a Fiber is created.
 
static FiberHookhookDead = nullptr
 Hook to be called when a Fiber is destroyed.
 
static uintptr_t const ExitUnknown = (uintptr_t)-1
 

Detailed Description

template<typename R>
class zth::TypedFiber< R >

Typed fiber class.

Template Parameters
RReturn type of the fiber function.

This is a virtual base class. Derive from this class and implement the entry function.

Dereferencing this fiber, forces the fiber to have a future, and the caller waits till the future completes.

Definition at line 55 of file async.h.

Member Typedef Documentation

◆ Future_type

template<typename R >
typedef Future<Return> zth::TypedFiber< R >::Future_type

Definition at line 59 of file async.h.

◆ Return

template<typename R >
typedef R zth::TypedFiber< R >::Return

Definition at line 58 of file async.h.

Constructor & Destructor Documentation

◆ TypedFiber()

template<typename R >
constexpr zth::TypedFiber< R >::TypedFiber ( )
inlineconstexpr

Definition at line 61 of file async.h.

◆ ~TypedFiber()

template<typename R >
virtual zth::TypedFiber< R >::~TypedFiber ( )
overridevirtualdefaultnoexcept

Member Function Documentation

◆ entry()

template<typename R >
static void zth::TypedFiber< R >::entry ( void *  that)
inlinestaticprotected

Definition at line 112 of file async.h.

◆ entry_()

template<typename R >
virtual void zth::TypedFiber< R >::entry_ ( )
protectedpure virtual

◆ future()

template<typename R >
Future_type * zth::TypedFiber< R >::future ( ) const
inline

Definition at line 82 of file async.h.

◆ operator SharedPointer< Future_type > const &()

template<typename R >
zth::TypedFiber< R >::operator SharedPointer< Future_type > const & ( )
inline

Definition at line 101 of file async.h.

◆ operator SharedReference< Future_type >()

template<typename R >
zth::TypedFiber< R >::operator SharedReference< Future_type > ( )
inline

Definition at line 106 of file async.h.

◆ registerFuture()

template<typename R >
void zth::TypedFiber< R >::registerFuture ( Future_type future)
inline

Definition at line 67 of file async.h.

◆ setFuture() [1/2]

template<typename R >
void zth::TypedFiber< R >::setFuture ( )
inlineprotected

Definition at line 139 of file async.h.

◆ setFuture() [2/2]

template<typename R >
template<typename T >
void zth::TypedFiber< R >::setFuture ( T const &  r)
inlineprotected

Definition at line 133 of file async.h.

◆ withFuture()

template<typename R >
SharedPointer< Future_type > const & zth::TypedFiber< R >::withFuture ( )
inline

Definition at line 87 of file async.h.


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