Lely core libraries  2.3.4
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  ev_future_t *future = ev_promise_get_future(promise);
47 
48  struct io_sigset_async_wait *async_wait = ev_promise_data(promise);
49  async_wait->promise = promise;
50  async_wait->wait = (struct io_sigset_wait)IO_SIGSET_WAIT_INIT(
51  exec, &io_sigset_async_wait_func);
52 
53  io_sigset_submit_wait(sigset, &async_wait->wait);
54 
55  if (pwait)
56  *pwait = &async_wait->wait;
57 
58  return future;
59 }
60 
61 struct io_sigset_wait *
63 {
64  return task ? structof(task, struct io_sigset_wait, task) : NULL;
65 }
66 
67 static void
68 io_sigset_async_wait_func(struct ev_task *task)
69 {
70  assert(task);
72  struct io_sigset_async_wait *async_wait =
73  structof(wait, struct io_sigset_async_wait, wait);
74 
75  ev_promise_set(async_wait->promise, &wait->signo);
76  ev_promise_release(async_wait->promise);
77 }
void ev_promise_release(ev_promise_t *promise)
Releases a reference to a promise.
Definition: future.c:198
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:242
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:312
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:154
void * ev_promise_data(const ev_promise_t *promise)
Returns a pointer to the shared state of a promise.
Definition: future.c:236
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
Definition: ev.h:29
This header file is part of the I/O library; it contains the abstract signal handler interface.
const struct io_sigset_vtbl *const io_sigset_t
An abstract signal handler.
Definition: sigset.h:40
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
#define IO_SIGSET_WAIT_INIT(exec, func)
The static initializer for io_sigset_wait.
Definition: sigset.h:54
This is the public header file of the utilities library.
#define structof(ptr, type, member)
Obtains the address of a structure from the address of one of its members.
Definition: util.h:93
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:62
This is the internal header file of the I/O library.
A future.
Definition: future.c:66
A promise.
Definition: future.c:95
An executable task.
Definition: task.h:41
A wait operation suitable for use with a signal handler.
Definition: sigset.h:43
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the wait operation.
Definition: sigset.h:48
int signo
The signal number, or 0 if the wait operation was canceled.
Definition: sigset.h:50