xref: /dpdk/lib/vhost/fd_man.h (revision 30a1de105a5f40d77b344a891c4a68f79e815c43)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4 
5 #ifndef _FD_MAN_H_
6 #define _FD_MAN_H_
7 #include <pthread.h>
8 #include <poll.h>
9 
10 #define MAX_FDS 1024
11 
12 typedef void (*fd_cb)(int fd, void *dat, int *remove);
13 
14 struct fdentry {
15 	int fd;		/* -1 indicates this entry is empty */
16 	fd_cb rcb;	/* callback when this fd is readable. */
17 	fd_cb wcb;	/* callback when this fd is writeable.*/
18 	void *dat;	/* fd context */
19 	int busy;	/* whether this entry is being used in cb. */
20 };
21 
22 struct fdset {
23 	struct pollfd rwfds[MAX_FDS];
24 	struct fdentry fd[MAX_FDS];
25 	pthread_mutex_t fd_mutex;
26 	pthread_mutex_t fd_pooling_mutex;
27 	int num;	/* current fd number of this fdset */
28 
29 	union pipefds {
30 		struct {
31 			int pipefd[2];
32 		};
33 		struct {
34 			int readfd;
35 			int writefd;
36 		};
37 	} u;
38 };
39 
40 
41 void fdset_init(struct fdset *pfdset);
42 
43 int fdset_add(struct fdset *pfdset, int fd,
44 	fd_cb rcb, fd_cb wcb, void *dat);
45 
46 void *fdset_del(struct fdset *pfdset, int fd);
47 int fdset_try_del(struct fdset *pfdset, int fd);
48 
49 void *fdset_event_dispatch(void *arg);
50 
51 int fdset_pipe_init(struct fdset *fdset);
52 
53 void fdset_pipe_uninit(struct fdset *fdset);
54 
55 void fdset_pipe_notify(struct fdset *fdset);
56 
57 #endif
58