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.12 by root, Sun Jun 23 23:02:09 2019 UTC vs.
Revision 1.14 by root, Sun Jun 23 23:49:56 2019 UTC

219static int 219static int
220linuxaio_get_events_from_ring (EV_P) 220linuxaio_get_events_from_ring (EV_P)
221{ 221{
222 struct aio_ring *ring = (struct aio_ring *)linuxaio_ctx; 222 struct aio_ring *ring = (struct aio_ring *)linuxaio_ctx;
223 223
224 unsigned head = ring->head; 224 /* the kernel reads and writes both of these variables, */
225 /* as a C extension, we assume that volatile use here */
226 /* both makes reads atomic and once-only */
227 unsigned head = *(volatile unsigned *)&ring->head;
225 unsigned tail = *(volatile unsigned *)&ring->tail; 228 unsigned tail = *(volatile unsigned *)&ring->tail;
226 229
227 if (head == tail) 230 if (head == tail)
228 return 0; 231 return 0;
229 232
243 { 246 {
244 linuxaio_parse_events (EV_A_ ring->io_events + head, ring->nr - head); 247 linuxaio_parse_events (EV_A_ ring->io_events + head, ring->nr - head);
245 linuxaio_parse_events (EV_A_ ring->io_events, tail); 248 linuxaio_parse_events (EV_A_ ring->io_events, tail);
246 } 249 }
247 250
251 /* as an extension to C, we hope that the volatile will makethis atomic and once-only */
248 *(volatile unsigned *)&ring->head = tail; 252 *(volatile unsigned *)&ring->head = tail;
249 /* make sure kernel can see our new head value - probably not required */ 253 /* make sure kernel can see our new head value - probably not required */
250 ECB_MEMORY_FENCE_RELEASE; 254 ECB_MEMORY_FENCE_RELEASE;
251 255
252 return 1; 256 return 1;
417 return 0; 421 return 0;
418 } 422 }
419 423
420 ev_io_init (EV_A_ &linuxaio_epoll_w, linuxaio_epoll_cb, backend_fd, EV_READ); 424 ev_io_init (EV_A_ &linuxaio_epoll_w, linuxaio_epoll_cb, backend_fd, EV_READ);
421 ev_io_start (EV_A_ &linuxaio_epoll_w); 425 ev_io_start (EV_A_ &linuxaio_epoll_w);
426 ev_unref (EV_A); /* watcher should not keep loop alive */
422#endif 427#endif
423 428
424 backend_modify = linuxaio_modify; 429 backend_modify = linuxaio_modify;
425 backend_poll = linuxaio_poll; 430 backend_poll = linuxaio_poll;
426 431
462 ev_syserr ("(libev) linuxaio epoll_create"); 467 ev_syserr ("(libev) linuxaio epoll_create");
463 468
464 ev_io_stop (EV_A_ &linuxaio_epoll_w); 469 ev_io_stop (EV_A_ &linuxaio_epoll_w);
465 ev_io_init (EV_A_ &linuxaio_epoll_w, linuxaio_epoll_cb, backend_fd, EV_READ); 470 ev_io_init (EV_A_ &linuxaio_epoll_w, linuxaio_epoll_cb, backend_fd, EV_READ);
466 ev_io_start (EV_A_ &linuxaio_epoll_w); 471 ev_io_start (EV_A_ &linuxaio_epoll_w);
467 ev_unref (EV_A); /* watcher should not keep loop alive */
468#endif 472#endif
469 473
470 fd_rearm_all (EV_A); 474 fd_rearm_all (EV_A);
471} 475}
472 476

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines