• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <poll.h>
13 
14 enum waiter_type {
15 	WAITER_TYPE_DEFAULT = 0,
16 	WAITER_TYPE_POLL,
17 	WAITER_TYPE_SELECT,
18 	WAITER_TYPE_EPOLL,
19 	WAITER_TYPE_COUNT,
20 };
21 
22 struct waiter_ops;
23 
24 struct waiter_context {
25 	enum waiter_type type;
26 	const struct waiter_ops *ops;
27 	void *private_data;
28 
29 	struct pollfd *pfds;
30 	unsigned int pfd_count;
31 };
32 
33 enum waiter_type waiter_type_from_label(const char *label);
34 const char *waiter_label_from_type(enum waiter_type type);
35 
36 int waiter_context_init(struct waiter_context *waiter,
37 			enum waiter_type type, unsigned int pfd_count);
38 int waiter_context_prepare(struct waiter_context *waiter);
39 int waiter_context_wait_event(struct waiter_context *waiter,
40 				int timeout_msec);
41 void waiter_context_release(struct waiter_context *waiter);
42 void waiter_context_destroy(struct waiter_context *waiter);
43 
44 // For internal use in 'waiter' module.
45 
46 struct waiter_ops {
47 	int (*prepare)(struct waiter_context *waiter);
48 	int (*wait_event)(struct waiter_context *waiter, int timeout_msec);
49 	void (*release)(struct waiter_context *waiter);
50 };
51 
52 struct waiter_data {
53 	struct waiter_ops ops;
54 	unsigned int private_size;
55 };
56 
57 extern const struct waiter_data waiter_poll;
58 extern const struct waiter_data waiter_select;
59 extern const struct waiter_data waiter_epoll;
60 
61 #endif
62