Lely core libraries  2.2.5
loop.h
Go to the documentation of this file.
1 
41 #ifndef LELY_EV_LOOP_H_
42 #define LELY_EV_LOOP_H_
43 
44 #include <lely/ev/future.h>
45 #include <lely/ev/poll.h>
46 #include <lely/libc/time.h>
47 
48 #include <stddef.h>
49 
50 #ifndef LELY_EV_LOOP_INLINE
51 #define LELY_EV_LOOP_INLINE static inline
52 #endif
53 
55 typedef struct ev_loop ev_loop_t;
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
61 void *ev_loop_alloc(void);
62 void ev_loop_free(void *ptr);
63 ev_loop_t *ev_loop_init(
64  ev_loop_t *loop, ev_poll_t *poll, size_t npoll, int poll_task);
65 void ev_loop_fini(ev_loop_t *loop);
66 
92 ev_loop_t *ev_loop_create(ev_poll_t *poll, size_t npoll, int poll_task);
93 
95 void ev_loop_destroy(ev_loop_t *loop);
96 
101 ev_poll_t *ev_loop_get_poll(const ev_loop_t *loop);
102 
104 ev_exec_t *ev_loop_get_exec(const ev_loop_t *loop);
105 
118 void ev_loop_stop(ev_loop_t *loop);
119 
121 int ev_loop_stopped(const ev_loop_t *loop);
122 
124 void ev_loop_restart(ev_loop_t *loop);
125 
135 size_t ev_loop_wait(ev_loop_t *loop, ev_future_t *future);
136 
146 size_t ev_loop_wait_until(ev_loop_t *loop, ev_future_t *future,
147  const struct timespec *abs_time);
148 
158 size_t ev_loop_wait_one(ev_loop_t *loop, ev_future_t *future);
159 
171 size_t ev_loop_wait_one_until(ev_loop_t *loop, ev_future_t *future,
172  const struct timespec *abs_time);
173 
175 LELY_EV_LOOP_INLINE size_t ev_loop_run(ev_loop_t *loop);
176 
178 LELY_EV_LOOP_INLINE size_t ev_loop_run_until(
179  ev_loop_t *loop, const struct timespec *abs_time);
180 
182 LELY_EV_LOOP_INLINE size_t ev_loop_run_one(ev_loop_t *loop);
183 
185 LELY_EV_LOOP_INLINE size_t ev_loop_run_one_until(
186  ev_loop_t *loop, const struct timespec *abs_time);
187 
189 LELY_EV_LOOP_INLINE size_t ev_loop_poll(ev_loop_t *loop);
190 
192 LELY_EV_LOOP_INLINE size_t ev_loop_poll_one(ev_loop_t *loop);
193 
199 void *ev_loop_self(void);
200 
208 int ev_loop_kill(ev_loop_t *loop, void *thr);
209 
210 inline size_t
212 {
213  return ev_loop_wait(loop, NULL);
214 }
215 
216 inline size_t
217 ev_loop_run_until(ev_loop_t *loop, const struct timespec *abs_time)
218 {
219  return ev_loop_wait_until(loop, NULL, abs_time);
220 }
221 
222 inline size_t
224 {
225  return ev_loop_wait_one(loop, NULL);
226 }
227 
228 inline size_t
229 ev_loop_run_one_until(ev_loop_t *loop, const struct timespec *abs_time)
230 {
231  return ev_loop_wait_one_until(loop, NULL, abs_time);
232 }
233 
234 inline size_t
236 {
237  return ev_loop_run_until(loop, NULL);
238 }
239 
240 inline size_t
242 {
243  return ev_loop_run_one_until(loop, NULL);
244 }
245 
246 #ifdef __cplusplus
247 }
248 #endif
249 
250 #endif // !LELY_EV_LOOP_H_
This header file is part of the event library; it contains the abstract polling interface.
const struct ev_poll_vtbl *const ev_poll_t
The abstract polling interface.
Definition: poll.h:32
This header file is part of the event library; it contains the futures and promises declarations.
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
Definition: ev.h:29
This header file is part of the C11 and POSIX compatibility library; it includes <time....
ev_exec_t * ev_loop_get_exec(const ev_loop_t *loop)
Returns a pointer to the executor corresponding to the event loop.
Definition: loop.c:330
size_t ev_loop_run_one(ev_loop_t *loop)
Equivalent to ev_loop_wait_one(loop, NULL).
Definition: loop.h:223
int ev_loop_kill(ev_loop_t *loop, void *thr)
Interrupts an event loop running on the specified thread.
Definition: loop.c:429
size_t ev_loop_wait_one(ev_loop_t *loop, ev_future_t *future)
If the event loop has pending tasks, runs a single task.
Definition: loop.c:404
void ev_loop_destroy(ev_loop_t *loop)
Destroys a polling event loop.
Definition: loop.c:313
size_t ev_loop_poll(ev_loop_t *loop)
Equivalent to ev_loop_run_until(loop, NULL).
Definition: loop.h:235
ev_poll_t * ev_loop_get_poll(const ev_loop_t *loop)
Returns a pointer to the polling instance used by the event loop, or NULL if the loop does not poll.
Definition: loop.c:322
size_t ev_loop_poll_one(ev_loop_t *loop)
Equivalent to ev_loop_run_one_until(loop, NULL).
Definition: loop.h:241
ev_loop_t * ev_loop_create(ev_poll_t *poll, size_t npoll, int poll_task)
Creates a new polling event loop.
Definition: loop.c:286
void * ev_loop_self(void)
Returns the identifier of the calling thread.
Definition: loop.c:423
size_t ev_loop_run_until(ev_loop_t *loop, const struct timespec *abs_time)
Equivalent to ev_loop_wait_until(loop, NULL, abs_time).
Definition: loop.h:217
size_t ev_loop_run(ev_loop_t *loop)
Equivalent to ev_loop_wait(loop, NULL).
Definition: loop.h:211
void ev_loop_stop(ev_loop_t *loop)
Stops the event loop.
Definition: loop.c:338
size_t ev_loop_wait(ev_loop_t *loop, ev_future_t *future)
Equivalent to.
Definition: loop.c:381
size_t ev_loop_wait_one_until(ev_loop_t *loop, ev_future_t *future, const struct timespec *abs_time)
If the event loop has pending tasks, runs a single task.
Definition: loop.c:413
size_t ev_loop_wait_until(ev_loop_t *loop, ev_future_t *future, const struct timespec *abs_time)
Equivalent to.
Definition: loop.c:392
size_t ev_loop_run_one_until(ev_loop_t *loop, const struct timespec *abs_time)
Equivalent to ev_loop_wait_one_until(loop, NULL, abs_time).
Definition: loop.h:229
int ev_loop_stopped(const ev_loop_t *loop)
Returns 1 if the event loop is stopped, and 0 if not.
Definition: loop.c:352
void ev_loop_restart(ev_loop_t *loop)
Restarts an event loop.
Definition: loop.c:367
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
A future.
Definition: future.c:63
A polling event loop.
Definition: loop.c:138
size_t npoll
The number of threads allowed to poll simultaneously.
Definition: loop.c:145
ev_poll_t * poll
A pointer to the interface used to poll for events (can be NULL).
Definition: loop.c:140