39 static void ev_strand_exec_on_task_init(
ev_exec_t *exec);
40 static void ev_strand_exec_on_task_fini(
ev_exec_t *exec);
47 &ev_strand_exec_on_task_init,
48 &ev_strand_exec_on_task_fini,
49 &ev_strand_exec_dispatch,
50 &ev_strand_exec_defer,
51 &ev_strand_exec_defer,
52 &ev_strand_exec_abort,
69 static void ev_strand_func(
struct ev_task *task);
74 static const int ev_strand_thrd;
82 struct ev_strand *strand = malloc(
sizeof(*strand));
86 return strand ? &strand->exec_vptr : NULL;
90 ev_strand_free(
void *ptr)
98 struct ev_strand *strand = ev_strand_from_exec(exec);
101 strand->exec_vptr = &ev_strand_exec_vtbl;
103 strand->inner_exec = inner_exec;
104 strand->task = (
struct ev_task)EV_TASK_INIT(
105 strand->inner_exec, &ev_strand_func);
124 struct ev_strand *strand = ev_strand_from_exec(exec);
126 ev_strand_exec_abort(exec, NULL);
136 while (strand->posted) {
158 ev_exec_t *tmp = ev_strand_init(exec, inner_exec);
168 ev_strand_free((
void *)exec);
178 ev_strand_fini(exec);
179 ev_strand_free((
void *)exec);
186 struct ev_strand *strand = ev_strand_from_exec(exec);
188 return strand->inner_exec;
192 ev_strand_exec_on_task_init(
ev_exec_t *exec)
194 struct ev_strand *strand = ev_strand_from_exec(exec);
200 ev_strand_exec_on_task_fini(
ev_exec_t *exec)
202 struct ev_strand *strand = ev_strand_from_exec(exec);
210 struct ev_strand *strand = ev_strand_from_exec(exec);
212 assert(!task->
exec || task->
exec == exec);
216 ev_strand_exec_on_task_init(exec);
221 if (strand->thr == &ev_strand_thrd) {
227 ev_strand_exec_on_task_fini(exec);
231 int post = !strand->posted;
245 struct ev_strand *strand = ev_strand_from_exec(exec);
247 assert(!task->
exec || task->
exec == exec);
251 ev_strand_exec_on_task_init(exec);
257 int post = !strand->posted;
269 struct ev_strand *strand = ev_strand_from_exec(exec);
287 ev_strand_exec_on_task_fini(exec);
294 ev_strand_func(
struct ev_task *task)
305 assert(!strand->thr);
306 strand->thr = &ev_strand_thrd;
310 assert(task->
exec == exec);
313 ev_strand_exec_on_task_fini(exec);
317 assert(strand->thr == &ev_strand_thrd);
320 assert(strand->posted == 1);
321 int post = strand->posted = !
sllist_empty(&strand->queue);
330 ev_strand_from_exec(
const ev_exec_t *exec)
void ev_exec_post(ev_exec_t *exec, struct ev_task *task)
Submits *task to *exec for execution.
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
ev_exec_t * ev_strand_get_inner_exec(const ev_exec_t *exec)
Returns a pointer to the inner executor of a strand.
void mtx_destroy(mtx_t *mtx)
Releases any resources used by the mutex at mtx.
Indicates that the requested operation succeeded.
void ev_exec_on_task_fini(ev_exec_t *exec)
Undoes the effect of a previous call to ev_exec_on_task_init().
size_t ev_exec_abort(ev_exec_t *exec, struct ev_task *task)
Aborts the specified task submitted to *exec, if it has not yet begun executing, or all pending tasks...
struct slnode * sllist_pop_front(struct sllist *list)
Pops a node from the front of a singly-linked list.
struct sllist * sllist_append(struct sllist *dst, struct sllist *src)
Appends the singly-linked list at src to the one at dst.
This header file is part of the event library; it contains the strand executor declarations.
struct slnode * sllist_remove(struct sllist *list, struct slnode *node)
Removes a node from a singly-linked list.
A mutex type that supports neither timeout nor test and return.
int mtx_unlock(mtx_t *mtx)
Unlocks the mutex at mtx.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
void sllist_push_back(struct sllist *list, struct slnode *node)
Pushes a node to the back of a singly-linked list.
This header file is part of the C11 and POSIX compatibility library; it includes <threads.h>, if it exists, and defines any missing functionality.
int mtx_lock(mtx_t *mtx)
Blocks until it locks the mutex at mtx.
pthread_mutex_t mtx_t
A complete object type that holds an identifier for a mutex.
This header file is part of the utilities library; it contains the native and platform-independent er...
ev_exec_t * exec
A pointer to the executor to which the task is (to be) submitted.
This header file is part of the C11 and POSIX compatibility library; it includes <stdatomic.h>, if it exists, and defines any missing functionality.
void ev_exec_on_task_init(ev_exec_t *exec)
Indicates to the specified executor that a task will be submitted for execution in the future...
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function...
void ev_strand_destroy(ev_exec_t *exec)
Destroys a strand executor.
void thrd_yield(void)
Endeavors to permit other threads to run, even if the current thread would ordinarily continue to run...
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
This header file is part of the C11 and POSIX compatibility library; it includes <stdint.h> and defines any missing functionality.
This header file is part of the event library; it contains the task declarations. ...
int sllist_empty(const struct sllist *list)
Returns 1 if the singly-linked list is empty, and 0 if not.
#define structof(ptr, type, member)
Obtains the address of a structure from the address of one of its members.
This header file is part of the event library; it contains the abstract task executor interface...
#define _Thread_local
An object whose identifier is declared with the storage-class specifier _Thread_local has thread stor...
struct ev_task * ev_task_from_node(struct slnode *node)
Converts a pointer to a node in a queue to the address of the task containing the node...
ev_task_func_t * func
The function to be invoked when the task is run.
ev_exec_t * ev_strand_create(ev_exec_t *inner_exec)
Creates a strand executor.
This header file is part of the C11 and POSIX compatibility library; it includes <stdlib.h> and defines any missing functionality.
void sllist_init(struct sllist *list)
Initializes a singly-linked list.
This is the internal header file of the event library.
This is the public header file of the utilities library.
int mtx_init(mtx_t *mtx, int type)
Creates a mutex object with properties indicated by type, which must have one of the four values: ...