ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev_linuxaio.c
(Generate patch)

Comparing libev/ev_linuxaio.c (file contents):
Revision 1.1 by root, Thu Jun 20 22:44:59 2019 UTC vs.
Revision 1.2 by root, Thu Jun 20 23:14:54 2019 UTC

36 * provisions above, a recipient may use your version of this file under 36 * provisions above, a recipient may use your version of this file under
37 * either the BSD or the GPL. 37 * either the BSD or the GPL.
38 */ 38 */
39 39
40#include <sys/time.h> /* actually linux/time.h, but we must assume they are compatible */ 40#include <sys/time.h> /* actually linux/time.h, but we must assume they are compatible */
41#include <poll.h>
41#include <linux/aio_abi.h> 42#include <linux/aio_abi.h>
42 43
43/* we try to fill 4kn pages exactly. 44/* we try to fill 4kn pages exactly.
44 * the ring buffer header is 32 bytes, every io event is 32 bytes. 45 * the ring buffer header is 32 bytes, every io event is 32 bytes.
45 * the kernel takes the io event number, doubles it, adds 2, adds the ring buffer 46 * the kernel takes the io event number, doubles it, adds 2, adds the ring buffer
121{ 122{
122 /* TODO: quite the overhead to allocate every iocb separately */ 123 /* TODO: quite the overhead to allocate every iocb separately */
123 while (count--) 124 while (count--)
124 { 125 {
125 *base = (ANIOCBP)ev_malloc (sizeof (**base)); 126 *base = (ANIOCBP)ev_malloc (sizeof (**base));
127 /* TODO: full zero initialize required? */
126 memset (*base, 0, sizeof (**base)); 128 memset (*base, 0, sizeof (**base));
127 /* would be nice to initialize fd/data as well */ 129 /* would be nice to initialize fd/data as well */
128 (*base)->io.aio_lio_opcode = IOCB_CMD_POLL; 130 (*base)->io.aio_lio_opcode = IOCB_CMD_POLL;
129 ++base; 131 ++base;
130 } 132 }
134linuxaio_free_iocbp (EV_P) 136linuxaio_free_iocbp (EV_P)
135{ 137{
136 while (linuxaio_iocbpmax--) 138 while (linuxaio_iocbpmax--)
137 ev_free (linuxaio_iocbps [linuxaio_iocbpmax]); 139 ev_free (linuxaio_iocbps [linuxaio_iocbpmax]);
138 140
141 /* next resize will completely reallocate the array */
139 linuxaio_iocbpmax = 0; 142 linuxaio_iocbpmax = 0;
143 linuxaio_submitcnt = 0; /* all pointers invalidated */
140} 144}
141 145
142static void 146static void
143linuxaio_modify (EV_P_ int fd, int oev, int nev) 147linuxaio_modify (EV_P_ int fd, int oev, int nev)
144{ 148{
145 /* TODO: full zero initialize required? */
146 array_needsize (ANIOCBP, linuxaio_iocbps, linuxaio_iocbpmax, fd + 1, linuxaio_array_needsize_iocbp); 149 array_needsize (ANIOCBP, linuxaio_iocbps, linuxaio_iocbpmax, fd + 1, linuxaio_array_needsize_iocbp);
147 struct aniocb *iocb = linuxaio_iocbps [fd]; 150 struct aniocb *iocb = linuxaio_iocbps [fd];
148 151
149 if (iocb->io.aio_buf) 152 if (iocb->io.aio_buf)
150 ev_io_cancel (linuxaio_ctx, &iocb->io, (void *)0); 153 ev_io_cancel (linuxaio_ctx, &iocb->io, (struct io_event *)0);
151 154
152 if (nev) 155 if (nev)
153 { 156 {
154 iocb->io.aio_data = fd; 157 iocb->io.aio_data = fd;
155 iocb->io.aio_fildes = fd; 158 iocb->io.aio_fildes = fd;
171 while (nr) 174 while (nr)
172 { 175 {
173 int fd = ev->data; 176 int fd = ev->data;
174 int res = ev->res; 177 int res = ev->res;
175 178
176 assert (("libev: iocb fd must be in-bounds", fd >= 0 && fd < anfdxmax)); 179 assert (("libev: iocb fd must be in-bounds", fd >= 0 && fd < anfdmax));
177 180
178 /* linux aio is oneshot: rearm fd */ 181 /* linux aio is oneshot: rearm fd */
179 linuxaio_iocbps [fd]->io.aio_buf = 0; 182 linuxaio_iocbps [fd]->io.aio_buf = 0;
180 anfds [fd].events = 0; 183 anfds [fd].events = 0;
181 fd_change (EV_A_ fd, 0); 184 fd_change (EV_A_ fd, 0);
304inline_size 307inline_size
305int 308int
306linuxaio_init (EV_P_ int flags) 309linuxaio_init (EV_P_ int flags)
307{ 310{
308 /* would be great to have a nice test for IOCB_CMD_POLL instead */ 311 /* would be great to have a nice test for IOCB_CMD_POLL instead */
312 /* also: test some semi-common fd types, such as files and ttys in recommended_backends */
309 if (ev_linux_version () < 0x041200) /* 4.18 introduced IOCB_CMD_POLL */ 313 if (ev_linux_version () < 0x041200) /* 4.18 introduced IOCB_CMD_POLL */
310 return 0; 314 return 0;
311 315
312 if (ev_io_setup (EV_LINUXAIO_DEPTH, &linuxaio_ctx) < 0) 316 if (ev_io_setup (EV_LINUXAIO_DEPTH, &linuxaio_ctx) < 0)
313 return 0; 317 return 0;
335 339
336inline_size 340inline_size
337void 341void
338linuxaio_fork (EV_P) 342linuxaio_fork (EV_P)
339{ 343{
340 abort ();//D 344 /* TODO: verify and test */
341} 345 linuxaio_destroy (EV_A);
342 346
347 while (ev_io_setup (EV_LINUXAIO_DEPTH, &linuxaio_ctx) < 0)
348 ev_syserr ("(libev) io_setup");
349
350 fd_rearm_all (EV_A);
351}
352

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines