1 /* Copyright (C) 1997-2022 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3 
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8 
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <https://www.gnu.org/licenses/>.  */
17 
18 #ifndef _AIO_MISC_H
19 #define _AIO_MISC_H	1
20 
21 #include <aio.h>
22 #include <pthread.h>
23 
24 
25 /* Extend the operation enum.  */
26 enum
27 {
28   LIO_DSYNC = LIO_NOP + 1,
29   LIO_SYNC,
30   LIO_READ64 = LIO_READ | 128,
31   LIO_WRITE64 = LIO_WRITE | 128
32 };
33 
34 
35 /* Union of the two request types.  */
36 typedef union
37   {
38     struct aiocb aiocb;
39     struct aiocb64 aiocb64;
40   } aiocb_union;
41 
42 
43 /* Used to synchronize.  */
44 struct waitlist
45   {
46     struct waitlist *next;
47 
48     /* The next two fields is used in synchronous `lio_listio' operations.  */
49 #ifndef DONT_NEED_AIO_MISC_COND
50     pthread_cond_t *cond;
51 #endif
52     int *result;
53 
54     volatile unsigned int *counterp;
55     /* The next field is used in asynchronous `lio_listio' operations.  */
56     struct sigevent *sigevp;
57   };
58 
59 
60 /* Status of a request.  */
61 enum
62 {
63   no,
64   queued,
65   yes,
66   allocated,
67   done
68 };
69 
70 
71 /* Used to queue requests..  */
72 struct requestlist
73   {
74     int running;
75 
76     struct requestlist *last_fd;
77     struct requestlist *next_fd;
78     struct requestlist *next_prio;
79     struct requestlist *next_run;
80 
81     /* Pointer to the actual data.  */
82     aiocb_union *aiocbp;
83 
84     /* List of waiting processes.  */
85     struct waitlist *waiting;
86   };
87 
88 
89 /* Lock for global I/O list of requests.  */
90 extern pthread_mutex_t __aio_requests_mutex attribute_hidden;
91 
92 
93 /* Enqueue request.  */
94 extern struct requestlist *__aio_enqueue_request (aiocb_union *aiocbp,
95 						  int operation)
96   attribute_hidden;
97 
98 /* Find request entry for given AIO control block.  */
99 extern struct requestlist *__aio_find_req (aiocb_union *elem) attribute_hidden;
100 
101 /* Find request entry for given file descriptor.  */
102 extern struct requestlist *__aio_find_req_fd (int fildes) attribute_hidden;
103 
104 /* Remove request from the list.  */
105 extern void __aio_remove_request (struct requestlist *last,
106 				  struct requestlist *req, int all)
107   attribute_hidden;
108 
109 /* Release the entry for the request.  */
110 extern void __aio_free_request (struct requestlist *req) attribute_hidden;
111 
112 /* Notify initiator of request and tell this everybody listening.  */
113 extern void __aio_notify (struct requestlist *req) attribute_hidden;
114 
115 /* Notify initiator of request.  */
116 extern int __aio_notify_only (struct sigevent *sigev) attribute_hidden;
117 
118 /* Send the signal.  */
119 extern int __aio_sigqueue (int sig, const union sigval val, pid_t caller_pid)
120   attribute_hidden;
121 
122 #endif /* aio_misc.h */
123