xref: /third_party/alsa-utils/axfer/waiter.h (revision c72fcc34)
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
15enum 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
23struct waiter_ops;
24
25struct 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
34enum waiter_type waiter_type_from_label(const char *label);
35const char *waiter_label_from_type(enum waiter_type type);
36
37int waiter_context_init(struct waiter_context *waiter,
38			enum waiter_type type, unsigned int pfd_count);
39int waiter_context_prepare(struct waiter_context *waiter);
40int waiter_context_wait_event(struct waiter_context *waiter,
41				int timeout_msec);
42void waiter_context_release(struct waiter_context *waiter);
43void waiter_context_destroy(struct waiter_context *waiter);
44
45// For internal use in 'waiter' module.
46
47struct 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
53struct waiter_data {
54	struct waiter_ops ops;
55	unsigned int private_size;
56};
57
58extern const struct waiter_data waiter_poll;
59extern const struct waiter_data waiter_select;
60extern const struct waiter_data waiter_epoll;
61
62#endif
63