Lely core libraries  2.3.4
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 
175 size_t ev_loop_wait_one_until(ev_loop_t *loop, ev_future_t *future,
176  const struct timespec *abs_time);
177 
179 LELY_EV_LOOP_INLINE size_t ev_loop_run(ev_loop_t *loop);
180 
182 LELY_EV_LOOP_INLINE size_t ev_loop_run_until(
183  ev_loop_t *loop, const struct timespec *abs_time);
184 
186 LELY_EV_LOOP_INLINE size_t ev_loop_run_one(ev_loop_t *loop);
187 
189 LELY_EV_LOOP_INLINE size_t ev_loop_run_one_until(
190  ev_loop_t *loop, const struct timespec *abs_time);
191 
193 LELY_EV_LOOP_INLINE size_t ev_loop_poll(ev_loop_t *loop);
194 
196 LELY_EV_LOOP_INLINE size_t ev_loop_poll_one(ev_loop_t *loop);
197 
203 void *ev_loop_self(void);
204 
212 int ev_loop_kill(ev_loop_t *loop, void *thr);
213 
214 inline size_t
216 {
217  return ev_loop_wait(loop, NULL);
218 }
219 
220 inline size_t
221 ev_loop_run_until(ev_loop_t *loop, const struct timespec *abs_time)
222 {
223  return ev_loop_wait_until(loop, NULL, abs_time);
224 }
225 
226 inline size_t
228 {
229  return ev_loop_wait_one(loop, NULL);
230 }
231 
232 inline size_t
233 ev_loop_run_one_until(ev_loop_t *loop, const struct timespec *abs_time)
234 {
235  return ev_loop_wait_one_until(loop, NULL, abs_time);
236 }
237 
238 inline size_t
240 {
241  return ev_loop_run_until(loop, NULL);
242 }
243 
244 inline size_t
246 {
247  return ev_loop_run_one_until(loop, NULL);
248 }
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 
254 #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:335
size_t ev_loop_run_one(ev_loop_t *loop)
Equivalent to ev_loop_wait_one(loop, NULL).
Definition: loop.h:227
int ev_loop_kill(ev_loop_t *loop, void *thr)
Interrupts an event loop running on the specified thread.
Definition: loop.c:434
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:409
void ev_loop_destroy(ev_loop_t *loop)
Destroys a polling event loop.
Definition: loop.c:318
size_t ev_loop_poll(ev_loop_t *loop)
Equivalent to ev_loop_run_until(loop, NULL).
Definition: loop.h:239
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:327
size_t ev_loop_poll_one(ev_loop_t *loop)
Equivalent to ev_loop_run_one_until(loop, NULL).
Definition: loop.h:245
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:291
void * ev_loop_self(void)
Returns the identifier of the calling thread.
Definition: loop.c:428
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:221
size_t ev_loop_run(ev_loop_t *loop)
Equivalent to ev_loop_wait(loop, NULL).
Definition: loop.h:215
void ev_loop_stop(ev_loop_t *loop)
Stops the event loop.
Definition: loop.c:343
size_t ev_loop_wait(ev_loop_t *loop, ev_future_t *future)
Equivalent to.
Definition: loop.c:386
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:418
size_t ev_loop_wait_until(ev_loop_t *loop, ev_future_t *future, const struct timespec *abs_time)
Equivalent to.
Definition: loop.c:397
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:233
int ev_loop_stopped(const ev_loop_t *loop)
Returns 1 if the event loop is stopped, and 0 if not.
Definition: loop.c:357
void ev_loop_restart(ev_loop_t *loop)
Restarts an event loop.
Definition: loop.c:372
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
A future.
Definition: future.c:66
A polling event loop.
Definition: loop.c:141
size_t npoll
The number of threads allowed to poll simultaneously.
Definition: loop.c:148
ev_poll_t * poll
A pointer to the interface used to poll for events (can be NULL).
Definition: loop.c:143