doc: add Meson coding style to contributors guide
[dpdk.git] / lib / librte_vhost / fd_man.h
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 <stdint.h>
8 #include <pthread.h>
9 #include <poll.h>
10
11 #define MAX_FDS 1024
12
13 typedef void (*fd_cb)(int fd, void *dat, int *remove);
14
15 struct fdentry {
16         int fd;         /* -1 indicates this entry is empty */
17         fd_cb rcb;      /* callback when this fd is readable. */
18         fd_cb wcb;      /* callback when this fd is writeable.*/
19         void *dat;      /* fd context */
20         int busy;       /* whether this entry is being used in cb. */
21 };
22
23 struct fdset {
24         struct pollfd rwfds[MAX_FDS];
25         struct fdentry fd[MAX_FDS];
26         pthread_mutex_t fd_mutex;
27         pthread_mutex_t fd_pooling_mutex;
28         int num;        /* current fd number of this fdset */
29
30         union pipefds {
31                 struct {
32                         int pipefd[2];
33                 };
34                 struct {
35                         int readfd;
36                         int writefd;
37                 };
38         } u;
39 };
40
41
42 void fdset_init(struct fdset *pfdset);
43
44 int fdset_add(struct fdset *pfdset, int fd,
45         fd_cb rcb, fd_cb wcb, void *dat);
46
47 void *fdset_del(struct fdset *pfdset, int fd);
48 int fdset_try_del(struct fdset *pfdset, int fd);
49
50 void *fdset_event_dispatch(void *arg);
51
52 int fdset_pipe_init(struct fdset *fdset);
53
54 void fdset_pipe_uninit(struct fdset *fdset);
55
56 void fdset_pipe_notify(struct fdset *fdset);
57
58 #endif