Module fiber
Fiber - contains information about a fiber.
Function to run inside a fiber.
Create a new fiber.
Takes a fiber from the fiber cache, if it's not empty. Can fail only if there is not enough memory for the fiber structure or fiber stack.
The created fiber automatically returns itself to the fiber cache when its "main" function completes.
Parameters:
-
name(const char*) — string with fiber name -
f(fiber_func) — func for run inside fiber
See also: fiber_start()
Create a new fiber with defined attributes.
Can fail only if there is not enough memory for the fiber structure or fiber stack.
The created fiber automatically returns itself to the fiber cache if has a default stack size when its "main" function completes.
-
name(const char*) — string with fiber name -
fiber_attr(const struct fiber_attr*) — fiber attributes container -
f(fiber_func) — function to run inside the fiber
See also: fiber_start()
Start execution of created fiber.
-
callee(struct fiber*) — fiber to start -
...— arguments to start the fiber with
Return control to another fiber and wait until it'll be woken.
See also: fiber_wakeup()
Interrupt a synchronous wait of a fiber
f(struct fiber*) — fiber to be woken up
Cancel the subject fiber.
Cancellation is asynchronous. Use fiber_join() to wait for the cancellation to complete.
After fiber_cancel() is called, the fiber may or may not check
whether it was cancelled. If the fiber does not check it, it cannot
ever be cancelled.
f(struct fiber*) — fiber to be cancelled
Deprecated since 2.11.0. Make it possible or not possible to wakeup the current fiber immediately when it's cancelled.
-
f(struct fiber*) — fiber -
yesno(bool) — status to set
Returns
previous state
Set fiber to be joinable (false by default).
-
f(struct fiber*) — fiber -
yesno(bool) — status to set
Wait until the fiber is dead and then move its execution status to the caller. The fiber must not be detached.
f(struct fiber*) — fiber to be woken up
Before: FIBER_IS_JOINABLE flag is set.
See also: fiber_set_joinable()
Put the current fiber to sleep for at least 's' seconds.
s(double) — time to sleep
Note: this is a cancellation point.
See also: fiber_is_cancelled()
Check current fiber for cancellation (it must be checked manually).
Report loop begin time as double (cheap).
Report loop begin time as 64-bit int. Uses real time clock.
Report loop begin time as double (cheap). Uses monotonic clock.
Report loop begin time as 64-bit int. Uses monotonic clock.
Reschedule fiber to end of event loop cycle.
Return slab_cache suitable to use with tarantool/small library
Return the current fiber.
Create a new fiber attributes container and initialize it with default parameters.
Can be used for creating many fibers: corresponding fibers will not take ownership.
Delete the fiber_attr and free all allocated resources. This is safe
when fibers created with this attribute still exist.
fiber_attribute(struct fiber_attr*) — fiber attributes container
Set the fiber's stack size in the fiber attributes container.
-
fiber_attr(struct fiber_attr*) — fiber attributes container -
stack_size(size_t) — stack size for new fibers (in bytes)
Returns
0 on success
Returns
-1 on failure (if stack_size is smaller than the minimum
allowable fiber stack size)
Get the fiber's stack size from the fiber attributes container.
fiber_attr(struct fiber_attr*) — fiber attributes container, or NULL for default
Returns
stack size (in bytes)
A conditional variable: a synchronization primitive that allow fibers in Tarantool's cooperative multitasking environment to yield until some predicate is satisfied.
Fiber conditions have two basic operations – "wait" and "signal", – where "wait" suspends the execution of a fiber (i.e. yields) until "signal" is called.
Unlike pthread_cond, fiber_cond doesn't require mutex/latch
wrapping.
Create a new conditional variable.
Delete the conditional variable.
Note: behavior is undefined if there are fibers waiting for the conditional variable.
cond(struct fiber_cond*) — conditional variable to delete
Wake up one (any) of the fibers waiting for the conditional variable.
Does nothing if no one is waiting.
cond(struct fiber_cond*) — conditional variable
Wake up all fibers waiting for the conditional variable.
Does nothing if no one is waiting.
cond(struct fiber_cond*) — conditional variable
Suspend the execution of the current fiber (i.e. yield) until fiber_cond_signal() is called.
Like pthread_cond, fiber_cond can issue spurious wake ups caused
by explicit fiber_wakeup() or
fiber_cancel() calls. It is highly
recommended to wrap calls to this function into a loop and check the
actual predicate and
fiber_is_cancelled() on every
iteration.
-
cond(struct fiber_cond*) — conditional variable -
timeout(double) — timeout in seconds
Returns
0 on fiber_cond_signal() call or a spurious wake up
Returns
-1 on timeout, and the error code is set to 'TimedOut'
Shortcut for fiber_cond_wait_timeout().