blob: e311453cb91a5fb43a902e145206d00700863301 [file] [log] [blame]
Amit Pundir33109f72020-02-07 22:26:08 +05301#ifndef _WAITER_H_
2#define _WAITER_H_
3
4/** Waiter type. */
5struct waiter;
6
7/** Create a new waiter.
8 * @return Newly created waiter on success, NULL on failure.
9 */
10struct waiter *waiter_create(void);
11
12/** Destroy existing waiter.
13 * @param w waiter to destroy.
14 */
15void waiter_destroy(struct waiter *w);
16
17/** Wait for next ticket.
18 * @param w waiter.
19 */
20void waiter_wait(struct waiter *w);
21
22/** Wait for next ticket or timeout.
23 * @param w waiter.
24 * @param ms timeout in milliseconds.
25 * @return 0 on ticket; !0 on timeout.
26 */
27int waiter_wait_timeout(struct waiter *w, unsigned int ms);
28
29/** Synchronize timer-based tickets.
30 * @param w waiter.
31 */
32void waiter_synchronize(struct waiter *w);
33
34/** Waiter ticket type. */
35struct waiter_ticket;
36
37/** Add a null wait ticket to pool.
38 * @param w waiter
39 * @return wait ticket on success; NULL on failure.
40 */
41struct waiter_ticket *waiter_add_null(struct waiter *w);
42
43/** Add a file descriptor to the pool.
44 * @param w waiter.
45 * @param fd file descriptor.
46 * @return wait ticket on success; NULL on failure.
47 */
48struct waiter_ticket *waiter_add_fd(struct waiter *w, int fd);
49
50/** Add a timeout to the pool.
51 * @param w waiter.
52 * @param ms duration of timeout in milliseconds.
53 * @return wait ticket on success; NULL on failure.
54 */
55struct waiter_ticket *waiter_add_timeout(struct waiter *w, unsigned int ms);
56
57/** Set ticket type to null.
58 * @param tkt wait ticket.
59 */
60void waiter_ticket_set_null(struct waiter_ticket *tkt);
61
62/** Set ticket type to file descriptor.
63 * @param tkt wait ticket.
64 * @param fd file descriptor.
65 */
66void waiter_ticket_set_fd(struct waiter_ticket *tkt, int fd);
67
68/** Set ticket type to timeout.
69 * @param tkt wait ticket.
70 * @param ms timeout in milliseconds.
71 */
72void waiter_ticket_set_timeout(struct waiter_ticket *tkt, unsigned int ms);
73
74/** Destroy ticket.
75 * @param tkt wait ticket.
76 */
77void waiter_ticket_delete(struct waiter_ticket *tkt);
78
79/** Check to see if ticket has triggered.
80 * @param tkt wait ticket.
81 * @return 0 if triggered, !0 otherwise.
82 */
83int waiter_ticket_check(const struct waiter_ticket *tkt);
84
85
86/** Clear ticket trigger status.
87 * @param tkt wait ticket.
88 * @return 0 if triggered, !0 otherwise.
89 */
90int waiter_ticket_clear(struct waiter_ticket *tkt);
91
92/** Wait ticket callback function type. */
93typedef void (* waiter_ticket_cb_t)(void *, struct waiter_ticket *);
94
95/** Register callback function for ticket trigger.
96 * @param tkt wait ticket.
97 * @param cb_fn callback function.
98 * @param data private data to pass to callback function.
99 */
100void waiter_ticket_callback(struct waiter_ticket *tkt,
101 waiter_ticket_cb_t cb_fn, void *data);
102
103#endif