Lely core libraries
2.2.5
|
Go to the documentation of this file.
48 #define FIBER_SIZE ALIGN(sizeof(fiber_t), _Alignof(max_align_t))
60 static _Noreturn void CALLBACK fiber_start(
void *arg);
70 SetLastError(ERROR_INVALID_PARAMETER);
77 assert(!thr->main.lpFiber);
78 assert(!thr->main.from);
81 thr->main.flags = flags;
84 dwFlags |= FIBER_FLAG_FLOAT_SWITCH;
85 thr->main.lpFiber = ConvertThreadToFiberEx(NULL, dwFlags);
86 if (!thr->main.lpFiber) {
92 thr->curr = &thr->main;
103 if (!--thr->refcnt) {
104 assert(thr->curr == &thr->main);
108 thr->main.from = NULL;
109 assert(thr->main.lpFiber);
110 ConvertFiberToThread();
111 thr->main.lpFiber = NULL;
121 SetLastError(ERROR_INVALID_PARAMETER);
134 dwErrCode = GetLastError();
135 goto error_malloc_fiber;
140 fiber->flags = flags;
148 dwFlags |= FIBER_FLAG_FLOAT_SWITCH;
149 fiber->lpFiber = CreateFiberEx(
150 stack_size, 0, dwFlags, &fiber_start,
fiber);
151 if (!
fiber->lpFiber) {
152 dwErrCode = GetLastError();
153 goto error_CreateFiberEx;
164 DeleteFiber(
fiber->lpFiber);
168 SetLastError(dwErrCode);
176 DeleteFiber(
fiber->lpFiber);
198 return fiber_switch(
fiber);
213 return fiber_switch(
fiber);
217 fiber_start(
void *arg)
236 void *arg =
fiber->arg;
260 assert(
fiber != curr);
263 curr->dwErrCode = GetLastError();
267 fiber->from = thr->curr;
269 assert(
fiber->lpFiber);
270 SwitchToFiber(
fiber->lpFiber);
271 assert(curr == thr->curr);
275 SetLastError(curr->dwErrCode);
281 void *arg = curr->arg;
283 curr->from = func(curr->from, arg);
fiber_t * fiber_create(fiber_func_t *func, void *arg, int flags, size_t data_size, size_t stack_size)
Creates a new fiber, allocates a stack and sets up a calling environment to begin executing the speci...
#define LELY_FIBER_STKSZ
The default size (in bytes) of a fiber stack frame.
void * fiber_data(const fiber_t *fiber)
Returns a pointer to the data region of the specified fiber, or of the calling fiber if fiber is NULL...
void fiber_destroy(fiber_t *fiber)
Destroys the specified fiber.
void fiber_thrd_fini(void)
Finalizes the fiber associated with the calling thread.
#define LELY_FIBER_MINSTKSZ
The minimum size (in bytes) of a fiber stack frame.
#define _Noreturn
A function declared with a _Noreturn function specifier SHALL not return to its caller.
#define FIBER_SAVE_ERROR
A flag specifying a fiber to save and restore the error values (i.e., errno and GetLastError() on Win...
fiber_t * fiber_resume(fiber_t *fiber)
Equivalent to fiber_resume_with(fiber, NULL, NULL).
fiber_t * fiber_func_t(fiber_t *fiber, void *arg)
The type of the function executed by a fiber.
#define _Thread_local
An object whose identifier is declared with the storage-class specifier _Thread_local has thread stor...
fiber_t * fiber_resume_with(fiber_t *fiber, fiber_func_t *func, void *arg)
Suspends the calling fiber and resumes the specified fiber, optionally executing a function before re...
int fiber_thrd_init(int flags)
Initializes the fiber associated with the calling thread.
#define FIBER_SAVE_ALL
A combination of those flags in FIBER_SAVE_MASK, FIBER_SAVE_FENV and FIBER_SAVE_ERROR that are suppor...
#define FIBER_SAVE_FENV
A flag specifying a fiber to save and restore the floating-point environment.