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

Comparing libev/ev.c (file contents):
Revision 1.516 by root, Tue Dec 24 13:24:29 2019 UTC vs.
Revision 1.520 by root, Sat Dec 28 07:44:15 2019 UTC

117# define EV_USE_EPOLL 0 117# define EV_USE_EPOLL 0
118# endif 118# endif
119 119
120# if HAVE_LINUX_AIO_ABI_H 120# if HAVE_LINUX_AIO_ABI_H
121# ifndef EV_USE_LINUXAIO 121# ifndef EV_USE_LINUXAIO
122# define EV_USE_LINUXAIO EV_FEATURE_BACKENDS 122# define EV_USE_LINUXAIO 0 /* was: EV_FEATURE_BACKENDS, always off by default */
123# endif 123# endif
124# else 124# else
125# undef EV_USE_LINUXAIO 125# undef EV_USE_LINUXAIO
126# define EV_USE_LINUXAIO 0 126# define EV_USE_LINUXAIO 0
127# endif 127# endif
344# define EV_USE_PORT 0 344# define EV_USE_PORT 0
345#endif 345#endif
346 346
347#ifndef EV_USE_LINUXAIO 347#ifndef EV_USE_LINUXAIO
348# if __linux /* libev currently assumes linux/aio_abi.h is always available on linux */ 348# if __linux /* libev currently assumes linux/aio_abi.h is always available on linux */
349# define EV_USE_LINUXAIO 1 349# define EV_USE_LINUXAIO 0 /* was: 1, always off by default */
350# else 350# else
351# define EV_USE_LINUXAIO 0 351# define EV_USE_LINUXAIO 0
352# endif 352# endif
353#endif 353#endif
354 354
1658 * our syscalls return < 0, not == -1, on error. which is good 1658 * our syscalls return < 0, not == -1, on error. which is good
1659 * enough for linux aio. 1659 * enough for linux aio.
1660 * TODO: arm is also common nowadays, maybe even mips and x86 1660 * TODO: arm is also common nowadays, maybe even mips and x86
1661 * TODO: after implementing this, it suddenly looks like overkill, but its hard to remove... 1661 * TODO: after implementing this, it suddenly looks like overkill, but its hard to remove...
1662 */ 1662 */
1663#if __GNUC__ && __linux && ECB_AMD64 && !defined __OPTIMIZE_SIZE__ 1663#if __GNUC__ && __linux && ECB_AMD64 && !EV_FEATURE_CODE
1664 /* the costly errno access probably kills this for size optimisation */ 1664 /* the costly errno access probably kills this for size optimisation */
1665 1665
1666 #define ev_syscall(nr,narg,arg1,arg2,arg3,arg4,arg5,arg6) \ 1666 #define ev_syscall(nr,narg,arg1,arg2,arg3,arg4,arg5,arg6) \
1667 ({ \ 1667 ({ \
1668 long res; \ 1668 long res; \
2262inline_size void 2262inline_size void
2263fd_reify (EV_P) 2263fd_reify (EV_P)
2264{ 2264{
2265 int i; 2265 int i;
2266 2266
2267 /* most backends do not modify the fdchanges list in backend_modfiy.
2268 * except io_uring, which has fixed-size buffers which might force us
2269 * to handle events in backend_modify, causing fdchangesd to be amended,
2270 * which could result in an endless loop.
2271 * to avoid this, we do not dynamically handle fds that were added
2272 * during fd_reify. that menas thast for those backends, fdchangecnt
2273 * might be non-zero during poll, which must cause them to not block.
2274 * to not put too much of a burden on other backends, this detail
2275 * needs to be handled in the backend.
2276 */
2277 int changecnt = fdchangecnt;
2278
2267#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP 2279#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP
2268 for (i = 0; i < fdchangecnt; ++i) 2280 for (i = 0; i < changecnt; ++i)
2269 { 2281 {
2270 int fd = fdchanges [i]; 2282 int fd = fdchanges [i];
2271 ANFD *anfd = anfds + fd; 2283 ANFD *anfd = anfds + fd;
2272 2284
2273 if (anfd->reify & EV__IOFDSET && anfd->head) 2285 if (anfd->reify & EV__IOFDSET && anfd->head)
2287 } 2299 }
2288 } 2300 }
2289 } 2301 }
2290#endif 2302#endif
2291 2303
2292 for (i = 0; i < fdchangecnt; ++i) 2304 for (i = 0; i < changecnt; ++i)
2293 { 2305 {
2294 int fd = fdchanges [i]; 2306 int fd = fdchanges [i];
2295 ANFD *anfd = anfds + fd; 2307 ANFD *anfd = anfds + fd;
2296 ev_io *w; 2308 ev_io *w;
2297 2309
2313 2325
2314 if (o_reify & EV__IOFDSET) 2326 if (o_reify & EV__IOFDSET)
2315 backend_modify (EV_A_ fd, o_events, anfd->events); 2327 backend_modify (EV_A_ fd, o_events, anfd->events);
2316 } 2328 }
2317 2329
2330 /* normally, fdchangecnt hasn't changed. if it has, then new fds have been added.
2331 * this is a rare case (see beginning comment in this function), so we copy them to the
2332 * front and hope the backend handles this case.
2333 */
2334 if (ecb_expect_false (fdchangecnt != changecnt))
2335 memmove (fdchanges, fdchanges + changecnt, (fdchangecnt - changecnt) * sizeof (*fdchanges));
2336
2318 fdchangecnt = 0; 2337 fdchangecnt -= changecnt;
2319} 2338}
2320 2339
2321/* something about the given fd changed */ 2340/* something about the given fd changed */
2322inline_size 2341inline_size
2323void 2342void
2982unsigned int 3001unsigned int
2983ev_supported_backends (void) EV_NOEXCEPT 3002ev_supported_backends (void) EV_NOEXCEPT
2984{ 3003{
2985 unsigned int flags = 0; 3004 unsigned int flags = 0;
2986 3005
2987 if (EV_USE_PORT ) flags |= EVBACKEND_PORT; 3006 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
2988 if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE; 3007 if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE;
2989 if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; 3008 if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL;
2990 if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO; 3009 if (EV_USE_LINUXAIO ) flags |= EVBACKEND_LINUXAIO;
2991 if (EV_USE_IOURING ) flags |= EVBACKEND_IOURING; 3010 if (EV_USE_IOURING && ev_linux_version () >= 0x050601) flags |= EVBACKEND_IOURING; /* 5.6.1+ */
2992 if (EV_USE_POLL ) flags |= EVBACKEND_POLL; 3011 if (EV_USE_POLL ) flags |= EVBACKEND_POLL;
2993 if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT; 3012 if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT;
2994 3013
2995 return flags; 3014 return flags;
2996} 3015}
2997 3016
2998ecb_cold 3017ecb_cold
2999unsigned int 3018unsigned int
5076 ev_run (EV_A_ EVRUN_NOWAIT); 5095 ev_run (EV_A_ EVRUN_NOWAIT);
5077 } 5096 }
5078 } 5097 }
5079} 5098}
5080 5099
5100#if EV_FORK_ENABLE
5081static void 5101static void
5082embed_fork_cb (EV_P_ ev_fork *fork_w, int revents) 5102embed_fork_cb (EV_P_ ev_fork *fork_w, int revents)
5083{ 5103{
5084 ev_embed *w = (ev_embed *)(((char *)fork_w) - offsetof (ev_embed, fork)); 5104 ev_embed *w = (ev_embed *)(((char *)fork_w) - offsetof (ev_embed, fork));
5085 5105
5092 ev_run (EV_A_ EVRUN_NOWAIT); 5112 ev_run (EV_A_ EVRUN_NOWAIT);
5093 } 5113 }
5094 5114
5095 ev_embed_start (EV_A_ w); 5115 ev_embed_start (EV_A_ w);
5096} 5116}
5117#endif
5097 5118
5098#if 0 5119#if 0
5099static void 5120static void
5100embed_idle_cb (EV_P_ ev_idle *idle, int revents) 5121embed_idle_cb (EV_P_ ev_idle *idle, int revents)
5101{ 5122{
5122 5143
5123 ev_prepare_init (&w->prepare, embed_prepare_cb); 5144 ev_prepare_init (&w->prepare, embed_prepare_cb);
5124 ev_set_priority (&w->prepare, EV_MINPRI); 5145 ev_set_priority (&w->prepare, EV_MINPRI);
5125 ev_prepare_start (EV_A_ &w->prepare); 5146 ev_prepare_start (EV_A_ &w->prepare);
5126 5147
5148#if EV_FORK_ENABLE
5127 ev_fork_init (&w->fork, embed_fork_cb); 5149 ev_fork_init (&w->fork, embed_fork_cb);
5128 ev_fork_start (EV_A_ &w->fork); 5150 ev_fork_start (EV_A_ &w->fork);
5151#endif
5129 5152
5130 /*ev_idle_init (&w->idle, e,bed_idle_cb);*/ 5153 /*ev_idle_init (&w->idle, e,bed_idle_cb);*/
5131 5154
5132 ev_start (EV_A_ (W)w, 1); 5155 ev_start (EV_A_ (W)w, 1);
5133 5156
5143 5166
5144 EV_FREQUENT_CHECK; 5167 EV_FREQUENT_CHECK;
5145 5168
5146 ev_io_stop (EV_A_ &w->io); 5169 ev_io_stop (EV_A_ &w->io);
5147 ev_prepare_stop (EV_A_ &w->prepare); 5170 ev_prepare_stop (EV_A_ &w->prepare);
5171#if EV_FORK_ENABLE
5148 ev_fork_stop (EV_A_ &w->fork); 5172 ev_fork_stop (EV_A_ &w->fork);
5173#endif
5149 5174
5150 ev_stop (EV_A_ (W)w); 5175 ev_stop (EV_A_ (W)w);
5151 5176
5152 EV_FREQUENT_CHECK; 5177 EV_FREQUENT_CHECK;
5153} 5178}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines