Zth (libzth)
Loading...
Searching...
No Matches
fiber

Classes

struct  zth_fiber_t
 Opaque fiber handle type. More...
 

Functions

int zth_fiber_create (zth_fiber_t *h, void(*f)(void *), void *arg=nullptr, size_t stack=0, char const *name=nullptr) noexcept
 Run a function as a new fiber.
 
void * zth_fls () noexcept
 Return the fiber-local storage, as set by setFls().
 
void zth_setFls (void *data=nullptr) noexcept
 Set the fiber-local storage.
 
void zth_nap (struct timespec const *ts)
 Sleep for the given time interval.
 
void zth_mnap (long sleepFor_ms)
 Sleep for the given amount of milliseconds.
 
void zth_unap (long sleepFor_us)
 Sleep for the given amount of microseconds.
 
void zth_yield () noexcept
 Allow a context switch.
 
void zth_outOfWork () noexcept
 Force a context switch.
 
int zth_worker_create () noexcept
 Create a Worker.
 
void zth_worker_run (struct timespec const *ts=nullptr) noexcept
 Run the worker for the given amount of time.
 
void zth_worker_destroy () noexcept
 Cleanup the worker.
 
int zth_startWorkerThread (void(*f)(), size_t stack=0, char const *name=nullptr) noexcept
 Start a new thread, create a Worker, with one fiber, which executes f.
 
int zth_execvp (char const *file, char *const arg[]) noexcept
 Start an external program.
 
zth_fiber_t zth_current_fiber () noexcept
 Return the currently executing fiber.
 

Detailed Description

Function Documentation

◆ zth_current_fiber()

zth_fiber_t zth_current_fiber ( )
noexcept

Return the currently executing fiber.

This is a C-wrapper for zth::currentFiber().

Definition at line 607 of file worker.h.

◆ zth_execvp()

int zth_execvp ( char const *  file,
char *const  arg[] 
)
noexcept

Start an external program.

This is a C-wrapper for zth::execvp().

Definition at line 597 of file worker.h.

◆ zth_fiber_create()

int zth_fiber_create ( zth_fiber_t h,
void(*)(void *)  f,
void *  arg = nullptr,
size_t  stack = 0,
char const *  name = nullptr 
)
noexcept

Run a function as a new fiber.

Examples
9_c_api.c.

Definition at line 1649 of file async.h.

◆ zth_fls()

void * zth_fls ( )
noexcept

Return the fiber-local storage, as set by setFls().

This is a C-wrapper for zth::fls().

Definition at line 655 of file fiber.h.

◆ zth_mnap()

void zth_mnap ( long  sleepFor_ms)

Sleep for the given amount of milliseconds.

This is a C-wrapper for zth::mnap().

Definition at line 422 of file waiter.h.

◆ zth_nap()

void zth_nap ( struct timespec const *  ts)

Sleep for the given time interval.

This is a C-wrapper for zth::nap(zth::TimeInterval const&).

Definition at line 411 of file waiter.h.

◆ zth_outOfWork()

void zth_outOfWork ( )
noexcept

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.

This is a C-wrapper for zth::outOfWork().

Definition at line 527 of file worker.h.

◆ zth_setFls()

void zth_setFls ( void *  data = nullptr)
noexcept

Set the fiber-local storage.

This is just like thread-local storage, but per fiber.

This is a C-wrapper for zth::setFls().

Definition at line 665 of file fiber.h.

◆ zth_startWorkerThread()

int zth_startWorkerThread ( void(*)()  f,
size_t  stack = 0,
char const *  name = nullptr 
)
noexcept

Start a new thread, create a Worker, with one fiber, which executes f.

This is a C-wrapper for zth::startWorkerThread().

Definition at line 587 of file worker.h.

◆ zth_unap()

void zth_unap ( long  sleepFor_us)

Sleep for the given amount of microseconds.

This is a C-wrapper for zth::unap().

Definition at line 432 of file waiter.h.

◆ zth_worker_create()

int zth_worker_create ( )
noexcept

Create a Worker.

Returns
0 on success, otherwise an errno
See also
zth_worker_run()
zth_worker_destroy()

Definition at line 539 of file worker.h.

◆ zth_worker_destroy()

void zth_worker_destroy ( )
noexcept

Cleanup the worker.

See also
zth_worker_create()

Definition at line 573 of file worker.h.

◆ zth_worker_run()

void zth_worker_run ( struct timespec const *  ts = nullptr)
noexcept

Run the worker for the given amount of time.

See also
zth_worker_create()

Definition at line 559 of file worker.h.

◆ zth_yield()

void zth_yield ( )
noexcept

Allow a context switch.

This is a C-wrapper for zth::yield().

Definition at line 517 of file worker.h.