Lely core libraries  2.2.5
sigset.c
Go to the documentation of this file.
1 
24 #include "io2.h"
25 #define LELY_IO_SIGSET_INLINE extern inline
26 #include <lely/io2/sigset.h>
27 #include <lely/util/util.h>
28 
29 #include <assert.h>
30 
32  ev_promise_t *promise;
33  struct io_sigset_wait wait;
34 };
35 
36 static void io_sigset_async_wait_func(struct ev_task *task);
37 
40  struct io_sigset_wait **pwait)
41 {
43  sizeof(struct io_sigset_async_wait), NULL);
44  if (!promise)
45  return NULL;
46 
47  struct io_sigset_async_wait *async_wait = ev_promise_data(promise);
48  async_wait->promise = promise;
49  async_wait->wait = (struct io_sigset_wait)IO_SIGSET_WAIT_INIT(
50  exec, &io_sigset_async_wait_func);
51 
52  io_sigset_submit_wait(sigset, &async_wait->wait);
53 
54  if (pwait)
55  *pwait = &async_wait->wait;
56 
57  return ev_promise_get_future(promise);
58 }
59 
60 struct io_sigset_wait *
62 {
63  return task ? structof(task, struct io_sigset_wait, task) : NULL;
64 }
65 
66 static void
67 io_sigset_async_wait_func(struct ev_task *task)
68 {
69  assert(task);
70  struct io_sigset_wait *wait = io_sigset_wait_from_task(task);
71  struct io_sigset_async_wait *async_wait =
72  structof(wait, struct io_sigset_async_wait, wait);
73 
74  ev_promise_set(async_wait->promise, &wait->signo);
75  ev_promise_release(async_wait->promise);
76 }
This header file is part of the I/O library; it contains the abstract signal handler interface...
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
Definition: ev.h:29
void * ev_promise_data(const ev_promise_t *promise)
Returns a pointer to the shared state of a promise.
Definition: future.c:233
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the wait operation.
Definition: sigset.h:48
void ev_promise_release(ev_promise_t *promise)
Releases a reference to a promise.
Definition: future.c:195
const struct io_sigset_vtbl *const io_sigset_t
An abstract signal handler.
Definition: sigset.h:40
int signo
The signal number, or 0 if the wait operation was canceled.
Definition: sigset.h:50
ev_promise_t * ev_promise_create(size_t size, ev_promise_dtor_t *dtor)
Constructs a new promise with an optional empty shared state.
Definition: future.c:151
A future.
Definition: future.c:63
A wait operation suitable for use with a signal handler.
Definition: sigset.h:43
void io_sigset_submit_wait(io_sigset_t *sigset, struct io_sigset_wait *wait)
Submits a wait operation to a signal handler.
Definition: sigset.h:223
ev_future_t * ev_promise_get_future(ev_promise_t *promise)
Returns (a reference to) a future associated with the specified promise.
Definition: future.c:309
ev_future_t * io_sigset_async_wait(io_sigset_t *sigset, ev_exec_t *exec, struct io_sigset_wait **pwait)
Submits an asynchronous wait operation to a signal handler and creates a future which becomes ready o...
Definition: sigset.c:39
struct io_sigset_wait * io_sigset_wait_from_task(struct ev_task *task)
Obtains a pointer to a signal wait operation from a pointer to its completion task.
Definition: sigset.c:61
An executable task.
Definition: task.h:41
#define structof(ptr, type, member)
Obtains the address of a structure from the address of one of its members.
Definition: util.h:93
int ev_promise_set(ev_promise_t *promise, void *value)
Satiesfies a promise, if it was not aready satisfied, and stores the specified value for retrieval by...
Definition: future.c:239
A promise.
Definition: future.c:92
This is the internal header file of the I/O library.
This is the public header file of the utilities library.