Zth (libzth)
fiber

Functions

int zth_fiber_create (void(*f)(void *), void *arg=nullptr, size_t stack=0, char const *name=nullptr) noexcept
 Run a function as 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_nap (struct timespec const *ts)
 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...
 
void zth_yield () noexcept
 Allow a context switch. More...
 
void zth_outOfWork () noexcept
 Force a context switch. More...
 
int zth_worker_create () noexcept
 Create a Worker. More...
 
void zth_worker_run (struct timespec const *ts=nullptr) noexcept
 Run the worker for the given amount of time. More...
 
void zth_worker_destroy () noexcept
 Cleanup the worker. More...
 
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. More...
 
int zth_execvp (char const *file, char *const arg[]) noexcept
 Start an external program. More...
 

Detailed Description

Function Documentation

◆ 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 568 of file worker.h.

◆ zth_fiber_create()

int zth_fiber_create ( 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 796 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 560 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 425 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 414 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 498 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 570 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 558 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 435 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 510 of file worker.h.

◆ zth_worker_destroy()

void zth_worker_destroy ( )
noexcept

Cleanup the worker.

See also
zth_worker_create()

Definition at line 544 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 530 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 488 of file worker.h.