1 #ifndef _WAITER_H_
2 #define _WAITER_H_
3 
4 /** Waiter type. */
5 struct waiter;
6 
7 /** Create a new waiter.
8  * @return Newly created waiter on success, NULL on failure.
9  */
10 struct waiter *waiter_create(void);
11 
12 /** Destroy existing waiter.
13  * @param w waiter to destroy.
14  */
15 void waiter_destroy(struct waiter *w);
16 
17 /** Wait for next ticket.
18  * @param w waiter.
19  */
20 void 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  */
27 int waiter_wait_timeout(struct waiter *w, unsigned int ms);
28 
29 /** Synchronize timer-based tickets.
30  * @param w waiter.
31  */
32 void waiter_synchronize(struct waiter *w);
33 
34 /** Waiter ticket type. */
35 struct 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  */
41 struct 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  */
48 struct 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  */
55 struct waiter_ticket *waiter_add_timeout(struct waiter *w, unsigned int ms);
56 
57 /** Set ticket type to null.
58  * @param tkt wait ticket.
59  */
60 void 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  */
66 void 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  */
72 void waiter_ticket_set_timeout(struct waiter_ticket *tkt, unsigned int ms);
73 
74 /** Destroy ticket.
75  * @param tkt wait ticket.
76  */
77 void 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  */
83 int 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  */
90 int waiter_ticket_clear(struct waiter_ticket *tkt);
91 
92 /** Wait ticket callback function type. */
93 typedef 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  */
100 void waiter_ticket_callback(struct waiter_ticket *tkt,
101 		waiter_ticket_cb_t cb_fn, void *data);
102 
103 #endif
104