1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // waiter.h - a header for I/O event waiter.
4 //
5 // Copyright (c) 2018 Takashi Sakamoto <o-takashi@sakamocchi.jp>
6 //
7 // Licensed under the terms of the GNU General Public License, version 2.
8 
9 #ifndef __ALSA_UTILS_AXFER_WAITER__H_
10 #define __ALSA_UTILS_AXFER_WAITER__H_
11 
12 #include <alsa/global.h>
13 #include <poll.h>
14 
15 enum waiter_type {
16 	WAITER_TYPE_DEFAULT = 0,
17 	WAITER_TYPE_POLL,
18 	WAITER_TYPE_SELECT,
19 	WAITER_TYPE_EPOLL,
20 	WAITER_TYPE_COUNT,
21 };
22 
23 struct waiter_ops;
24 
25 struct waiter_context {
26 	enum waiter_type type;
27 	const struct waiter_ops *ops;
28 	void *private_data;
29 
30 	struct pollfd *pfds;
31 	unsigned int pfd_count;
32 };
33 
34 enum waiter_type waiter_type_from_label(const char *label);
35 const char *waiter_label_from_type(enum waiter_type type);
36 
37 int waiter_context_init(struct waiter_context *waiter,
38 			enum waiter_type type, unsigned int pfd_count);
39 int waiter_context_prepare(struct waiter_context *waiter);
40 int waiter_context_wait_event(struct waiter_context *waiter,
41 				int timeout_msec);
42 void waiter_context_release(struct waiter_context *waiter);
43 void waiter_context_destroy(struct waiter_context *waiter);
44 
45 // For internal use in 'waiter' module.
46 
47 struct waiter_ops {
48 	int (*prepare)(struct waiter_context *waiter);
49 	int (*wait_event)(struct waiter_context *waiter, int timeout_msec);
50 	void (*release)(struct waiter_context *waiter);
51 };
52 
53 struct waiter_data {
54 	struct waiter_ops ops;
55 	unsigned int private_size;
56 };
57 
58 extern const struct waiter_data waiter_poll;
59 extern const struct waiter_data waiter_select;
60 extern const struct waiter_data waiter_epoll;
61 
62 #endif
63