1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#ifndef YASL_LOOP_H
#define YASL_LOOP_H
#include "yasl/yasl.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Optional event loop. Use the display's loop when adding application timers.
* A step waits at most timeout_ms: zero polls, a negative value waits indefinitely.
* Calls and callbacks use the loop's owning thread. */
YASL_API struct yasl_loop *yasl_loop_create(void);
YASL_API void yasl_loop_destroy(struct yasl_loop *l);
YASL_API int yasl_loop_run(struct yasl_loop *l);
YASL_API int yasl_loop_step(struct yasl_loop *l, int timeout_ms);
YASL_API void yasl_loop_quit(struct yasl_loop *l);
YASL_API void yasl_loop_kick(struct yasl_loop *l);
YASL_API uint64_t yasl_loop_now_ns(void);
YASL_API struct yasl_loop *yasl_display_loop(struct yasl_display *d);
YASL_API int yasl_loop_add_fd(struct yasl_loop *l, int fd, short events,
int (*fn)(int fd, short revents, void *ud), void *ud);
YASL_API int yasl_loop_del_fd(struct yasl_loop *l, int id);
YASL_API int yasl_loop_set_fd_events(struct yasl_loop *l, int id, short events);
/* Timers use nanoseconds. Return the next interval to repeat/reschedule, or zero
* to remove the timer. A zero ID indicates failure. Loop timers live until they
* stop, are deleted, or the loop is destroyed. Surface timers are also canceled
* when their surface is destroyed. */
typedef uint32_t yasl_timer_id;
typedef uint64_t (*yasl_timer_cb)(void *ud, yasl_timer_id id, uint64_t interval_ns);
#define YASL_MS_TO_NS(ms) ((uint64_t)(ms) * 1000000ull)
YASL_API yasl_timer_id yasl_loop_add_timer(struct yasl_loop *l, uint64_t interval_ns,
yasl_timer_cb cb, void *ud);
YASL_API bool yasl_loop_del_timer(struct yasl_loop *l, yasl_timer_id id);
YASL_API yasl_timer_id yasl_surface_add_timer(struct yasl_surface *s, uint64_t interval_ns,
yasl_timer_cb cb, void *ud);
YASL_API bool yasl_surface_del_timer(struct yasl_surface *s, yasl_timer_id id);
#ifdef __cplusplus
}
#endif
#endif /* YASL_LOOP_H */
|