… | |
… | |
268 | # include <winsock.h> |
268 | # include <winsock.h> |
269 | #endif |
269 | #endif |
270 | |
270 | |
271 | #if EV_USE_EVENTFD |
271 | #if EV_USE_EVENTFD |
272 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
272 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
|
|
273 | # include <stdint.h> |
|
|
274 | # ifdef __cplusplus |
|
|
275 | extern "C" { |
|
|
276 | # endif |
273 | int eventfd (unsigned int initval, int flags); |
277 | int eventfd (unsigned int initval, int flags); |
|
|
278 | # ifdef __cplusplus |
|
|
279 | } |
|
|
280 | # endif |
274 | #endif |
281 | #endif |
275 | |
282 | |
276 | /**/ |
283 | /**/ |
277 | |
284 | |
278 | /* |
285 | /* |
… | |
… | |
293 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
300 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
294 | # define noinline __attribute__ ((noinline)) |
301 | # define noinline __attribute__ ((noinline)) |
295 | #else |
302 | #else |
296 | # define expect(expr,value) (expr) |
303 | # define expect(expr,value) (expr) |
297 | # define noinline |
304 | # define noinline |
298 | # if __STDC_VERSION__ < 199901L |
305 | # if __STDC_VERSION__ < 199901L && __GNUC__ < 2 |
299 | # define inline |
306 | # define inline |
300 | # endif |
307 | # endif |
301 | #endif |
308 | #endif |
302 | |
309 | |
303 | #define expect_false(expr) expect ((expr) != 0, 0) |
310 | #define expect_false(expr) expect ((expr) != 0, 0) |
… | |
… | |
353 | perror (msg); |
360 | perror (msg); |
354 | abort (); |
361 | abort (); |
355 | } |
362 | } |
356 | } |
363 | } |
357 | |
364 | |
|
|
365 | static void * |
|
|
366 | ev_realloc_emul (void *ptr, long size) |
|
|
367 | { |
|
|
368 | /* some systems, notably openbsd and darwin, fail to properly |
|
|
369 | * implement realloc (x, 0) (as required by both ansi c-98 and |
|
|
370 | * the single unix specification, so work around them here. |
|
|
371 | */ |
|
|
372 | |
|
|
373 | if (size) |
|
|
374 | return realloc (ptr, size); |
|
|
375 | |
|
|
376 | free (ptr); |
|
|
377 | return 0; |
|
|
378 | } |
|
|
379 | |
358 | static void *(*alloc)(void *ptr, long size); |
380 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
359 | |
381 | |
360 | void |
382 | void |
361 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
383 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
362 | { |
384 | { |
363 | alloc = cb; |
385 | alloc = cb; |
364 | } |
386 | } |
365 | |
387 | |
366 | inline_speed void * |
388 | inline_speed void * |
367 | ev_realloc (void *ptr, long size) |
389 | ev_realloc (void *ptr, long size) |
368 | { |
390 | { |
369 | ptr = alloc ? alloc (ptr, size) : realloc (ptr, size); |
391 | ptr = alloc (ptr, size); |
370 | |
392 | |
371 | if (!ptr && size) |
393 | if (!ptr && size) |
372 | { |
394 | { |
373 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
395 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
374 | abort (); |
396 | abort (); |
… | |
… | |
732 | } |
754 | } |
733 | } |
755 | } |
734 | |
756 | |
735 | /*****************************************************************************/ |
757 | /*****************************************************************************/ |
736 | |
758 | |
|
|
759 | /* towards the root */ |
737 | void inline_speed |
760 | void inline_speed |
738 | upheap (WT *heap, int k) |
761 | upheap (WT *heap, int k) |
739 | { |
762 | { |
740 | WT w = heap [k]; |
763 | WT w = heap [k]; |
741 | |
764 | |
… | |
… | |
753 | |
776 | |
754 | heap [k] = w; |
777 | heap [k] = w; |
755 | ((W)heap [k])->active = k + 1; |
778 | ((W)heap [k])->active = k + 1; |
756 | } |
779 | } |
757 | |
780 | |
|
|
781 | /* away from the root */ |
758 | void inline_speed |
782 | void inline_speed |
759 | downheap (WT *heap, int N, int k) |
783 | downheap (WT *heap, int N, int k) |
760 | { |
784 | { |
761 | WT w = heap [k]; |
785 | WT w = heap [k]; |
762 | |
786 | |
… | |
… | |
1163 | if (!(flags & EVFLAG_NOENV) |
1187 | if (!(flags & EVFLAG_NOENV) |
1164 | && !enable_secure () |
1188 | && !enable_secure () |
1165 | && getenv ("LIBEV_FLAGS")) |
1189 | && getenv ("LIBEV_FLAGS")) |
1166 | flags = atoi (getenv ("LIBEV_FLAGS")); |
1190 | flags = atoi (getenv ("LIBEV_FLAGS")); |
1167 | |
1191 | |
1168 | if (!(flags & 0x0000ffffUL)) |
1192 | if (!(flags & 0x0000ffffU)) |
1169 | flags |= ev_recommended_backends (); |
1193 | flags |= ev_recommended_backends (); |
1170 | |
1194 | |
1171 | #if EV_USE_PORT |
1195 | #if EV_USE_PORT |
1172 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
1196 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
1173 | #endif |
1197 | #endif |
… | |
… | |
1261 | #endif |
1285 | #endif |
1262 | |
1286 | |
1263 | backend = 0; |
1287 | backend = 0; |
1264 | } |
1288 | } |
1265 | |
1289 | |
|
|
1290 | #if EV_USE_INOTIFY |
1266 | void inline_size infy_fork (EV_P); |
1291 | void inline_size infy_fork (EV_P); |
|
|
1292 | #endif |
1267 | |
1293 | |
1268 | void inline_size |
1294 | void inline_size |
1269 | loop_fork (EV_P) |
1295 | loop_fork (EV_P) |
1270 | { |
1296 | { |
1271 | #if EV_USE_PORT |
1297 | #if EV_USE_PORT |