Zth (libzth)
|
Classes | |
class | zth::setStackSize |
Change the stack size of a fiber returned by async. More... | |
class | zth::setName |
Change the name of a fiber returned by async. More... | |
class | zth::passOnExit |
Makes the fiber pass the given gate upon exit. More... | |
class | zth::PeriodicWakeUp |
Periodic wakeup after fixed interval. More... | |
class | zth::Worker |
The class that manages the fibers within this thread. More... | |
Macros | |
#define | zth_fiber_declare(...) |
Do the declaration part of zth_fiber() (to be used in an .h file). More... | |
#define | zth_fiber_define(...) |
Do the definition part of zth_fiber() (to be used in a .cpp file). More... | |
#define | zth_fiber(...) |
Prepare every given function to become a fiber by async. More... | |
#define | async |
Run a function as a new fiber. More... | |
Functions | |
template<typename F > | |
fiber_type< F >::factory | zth::fiber (F f, char const *name=nullptr) |
Create a new fiber. More... | |
void * | zth::fls () noexcept |
Return the fiber-local storage, as set by setFls(). More... | |
void | zth::setFls (void *data=nullptr) noexcept |
Set the fiber-local storage. More... | |
void | zth::waitUntil (TimedWaitable &w) |
Wait until the given Waitable has passed. More... | |
template<typename F , typename std::enable_if<!std::is_base_of< TimedWaitable, F >::value, int >::type = 0> | |
void | zth::waitUntil (F f, TimeInterval const &pollInterval=TimeInterval()) |
Wait until the given function f returns true . More... | |
template<typename C > | |
void | zth::waitUntil (C &that, bool(C::*f)(), TimeInterval const &pollInterval=TimeInterval()) |
Wait until the given member function f returns true . More... | |
void | zth::nap (Timestamp const &sleepUntil) |
Sleep until the given time stamp. More... | |
void | zth::nap (TimeInterval const &sleepFor) |
Sleep for the given time interval. More... | |
void | zth::mnap (long sleepFor_ms) |
Sleep for the given amount of milliseconds. More... | |
void | zth::unap (long sleepFor_us) |
Sleep for the given amount of microseconds. More... | |
Worker & | zth::currentWorker () noexcept |
Return the (thread-local) singleton Worker instance. More... | |
Fiber & | zth::currentFiber () noexcept |
Return the currently executing fiber. More... | |
void | zth::yield (Fiber *preferFiber=nullptr, bool alwaysYield=false, Timestamp const &now=Timestamp::now()) |
Allow a context switch. More... | |
void | zth::outOfWork () |
Force a context switch. More... | |
int | zth::startWorkerThread (void(*f)(), size_t stack, char const *name) |
Start a new thread, create a Worker, with one fiber, which executes f . More... | |
int | zth::execlp (char const *file, char const *arg,...) |
Start an external program. More... | |
int | zth::execvp (char const *file, char *const arg[]) |
Start an external program. More... | |
#define async |
Run a function as a new fiber.
The function must have passed through zth_fiber() (or friends) first. Example:
#define zth_fiber | ( | ... | ) |
Prepare every given function to become a fiber by async.
#define zth_fiber_declare | ( | ... | ) |
Do the declaration part of zth_fiber() (to be used in an .h file).
#define zth_fiber_define | ( | ... | ) |
Do the definition part of zth_fiber() (to be used in a .cpp file).
|
inlinenoexcept |
|
inlinenoexcept |
int zth::execlp | ( | char const * | file, |
char const * | arg, | ||
... | |||
) |
Start an external program.
Definition at line 96 of file worker.cpp.
int zth::execvp | ( | char const * | file, |
char *const | arg[] | ||
) |
Start an external program.
Definition at line 155 of file worker.cpp.
fiber_type<F>::factory zth::fiber | ( | F | f, |
char const * | name = nullptr |
||
) |
Create a new fiber.
Actually, it returns a factory, that allows passing the fiber arguments afterwards.
|
inlinenoexcept |
|
inline |
Sleep for the given amount of milliseconds.
|
inline |
|
inline |
Sleep until the given time stamp.
|
inline |
Force a context switch.
Normally, yield() does not yield when the time slice did not end. This prevents excessive context switching, without actually doing much work in between. However, if there is no work, this function forces a context switch anyway.
|
inlinenoexcept |
int zth::startWorkerThread | ( | void(*)() | f, |
size_t | stack = 0 , |
||
char const * | name = nullptr |
||
) |
Start a new thread, create a Worker, with one fiber, which executes f
.
Definition at line 65 of file worker.cpp.
|
inline |
void zth::waitUntil | ( | C & | that, |
bool(C::*)() | f, | ||
TimeInterval const & | pollInterval = TimeInterval() |
||
) |
void zth::waitUntil | ( | F | f, |
TimeInterval const & | pollInterval = TimeInterval() |
||
) |
void zth::waitUntil | ( | TimedWaitable & | w | ) |
Wait until the given Waitable has passed.
Definition at line 28 of file waiter.cpp.
|
inline |
Allow a context switch.
preferFiber | context switch to this fiber. Do normal scheduling when nullptr . |
alwaysYield | always perform a context switch, even if we are within Config::MinTimeslice_s(). |
now | the current time stamp |