… | |
… | |
464 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
464 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
465 | |
465 | |
466 | #define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0) |
466 | #define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0) |
467 | #define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9); } while (0) |
467 | #define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9); } while (0) |
468 | |
468 | |
469 | #if __GNUC__ >= 4 |
469 | /* the following are taken from libecb */ |
470 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
470 | /* ecb.h start */ |
471 | # define noinline __attribute__ ((noinline)) |
471 | |
|
|
472 | /* many compilers define _GNUC_ to some versions but then only implement |
|
|
473 | * what their idiot authors think are the "more important" extensions, |
|
|
474 | * causing enourmous grief in return for some better fake benchmark numbers. |
|
|
475 | * or so. |
|
|
476 | * we try to detect these and simply assume they are not gcc - if they have |
|
|
477 | * an issue with that they should have done it right in the first place. |
|
|
478 | */ |
|
|
479 | #ifndef ECB_GCC_VERSION |
|
|
480 | #if !defined(__GNUC_MINOR__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__llvm__) || defined(__clang__) |
|
|
481 | #define ECB_GCC_VERSION(major,minor) 0 |
|
|
482 | #else |
|
|
483 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
|
|
484 | #endif |
|
|
485 | #endif |
|
|
486 | |
|
|
487 | #if __cplusplus |
|
|
488 | #define ecb_inline static inline |
|
|
489 | #elif ECB_GCC_VERSION(2,5) |
|
|
490 | #define ecb_inline static __inline__ |
|
|
491 | #elif ECB_C99 |
|
|
492 | #define ecb_inline static inline |
472 | #else |
493 | #else |
473 | # define expect(expr,value) (expr) |
494 | #define ecb_inline static |
474 | # define noinline |
|
|
475 | # if __STDC_VERSION__ < 199901L && __GNUC__ < 2 |
|
|
476 | # define inline |
|
|
477 | # endif |
495 | #endif |
|
|
496 | |
|
|
497 | #ifndef ECB_MEMORY_FENCE |
|
|
498 | #if ECB_GCC_VERSION(2,5) |
|
|
499 | #if __x86 |
|
|
500 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
|
|
501 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
|
|
502 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
|
|
503 | #elif __amd64 |
|
|
504 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
|
|
505 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") |
|
|
506 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") |
|
|
507 | #endif |
478 | #endif |
508 | #endif |
|
|
509 | #endif |
479 | |
510 | |
|
|
511 | #ifndef ECB_MEMORY_FENCE |
|
|
512 | #if ECB_GCC_VERSION(4,4) |
|
|
513 | #define ECB_MEMORY_FENCE __sync_synchronize () |
|
|
514 | #define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) |
|
|
515 | #define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) |
|
|
516 | #elif defined(_WIN32) && defined(MemoryBarrier) |
|
|
517 | #define ECB_MEMORY_FENCE MemoryBarrier () |
|
|
518 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
|
|
519 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
|
|
520 | #endif |
|
|
521 | #endif |
|
|
522 | |
|
|
523 | #ifndef ECB_MEMORY_FENCE |
|
|
524 | #include <pthread.h> |
|
|
525 | |
|
|
526 | static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
|
|
527 | #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0) |
|
|
528 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
|
|
529 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
|
|
530 | #endif |
|
|
531 | |
|
|
532 | #if ECB_GCC_VERSION(3,1) |
|
|
533 | #define ecb_attribute(attrlist) __attribute__(attrlist) |
|
|
534 | #define ecb_is_constant(expr) __builtin_constant_p (expr) |
|
|
535 | #define ecb_expect(expr,value) __builtin_expect ((expr),(value)) |
|
|
536 | #define ecb_prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality) |
|
|
537 | #else |
|
|
538 | #define ecb_attribute(attrlist) |
|
|
539 | #define ecb_is_constant(expr) 0 |
|
|
540 | #define ecb_expect(expr,value) (expr) |
|
|
541 | #define ecb_prefetch(addr,rw,locality) |
|
|
542 | #endif |
|
|
543 | |
|
|
544 | #define ecb_noinline ecb_attribute ((__noinline__)) |
|
|
545 | #define ecb_noreturn ecb_attribute ((__noreturn__)) |
|
|
546 | #define ecb_unused ecb_attribute ((__unused__)) |
|
|
547 | #define ecb_const ecb_attribute ((__const__)) |
|
|
548 | #define ecb_pure ecb_attribute ((__pure__)) |
|
|
549 | |
|
|
550 | #if ECB_GCC_VERSION(4,3) |
|
|
551 | #define ecb_artificial ecb_attribute ((__artificial__)) |
|
|
552 | #define ecb_hot ecb_attribute ((__hot__)) |
|
|
553 | #define ecb_cold ecb_attribute ((__cold__)) |
|
|
554 | #else |
|
|
555 | #define ecb_artificial |
|
|
556 | #define ecb_hot |
|
|
557 | #define ecb_cold |
|
|
558 | #endif |
|
|
559 | |
|
|
560 | /* put around conditional expressions if you are very sure that the */ |
|
|
561 | /* expression is mostly true or mostly false. note that these return */ |
|
|
562 | /* booleans, not the expression. */ |
480 | #define expect_false(expr) expect ((expr) != 0, 0) |
563 | #define ecb_expect_false(expr) ecb_expect (!!(expr), 0) |
481 | #define expect_true(expr) expect ((expr) != 0, 1) |
564 | #define ecb_expect_true(expr) ecb_expect (!!(expr), 1) |
|
|
565 | /* ecb.h end */ |
|
|
566 | |
|
|
567 | #define expect_false(cond) ecb_expect_false (cond) |
|
|
568 | #define expect_true(cond) ecb_expect_true (cond) |
|
|
569 | #define noinline ecb_noinline |
|
|
570 | |
482 | #define inline_size static inline |
571 | #define inline_size ecb_inline |
483 | |
572 | |
484 | #if EV_FEATURE_CODE |
573 | #if EV_FEATURE_CODE |
485 | # define inline_speed static inline |
574 | # define inline_speed ecb_inline |
486 | #else |
575 | #else |
487 | # define inline_speed static noinline |
576 | # define inline_speed static noinline |
488 | #endif |
577 | #endif |
489 | |
578 | |
490 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
579 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
… | |
… | |
581 | |
670 | |
582 | #ifdef __linux |
671 | #ifdef __linux |
583 | # include <sys/utsname.h> |
672 | # include <sys/utsname.h> |
584 | #endif |
673 | #endif |
585 | |
674 | |
586 | static unsigned int noinline |
675 | static unsigned int noinline ecb_cold |
587 | ev_linux_version (void) |
676 | ev_linux_version (void) |
588 | { |
677 | { |
589 | #ifdef __linux |
678 | #ifdef __linux |
590 | unsigned int v = 0; |
679 | unsigned int v = 0; |
591 | struct utsname buf; |
680 | struct utsname buf; |
… | |
… | |
620 | } |
709 | } |
621 | |
710 | |
622 | /*****************************************************************************/ |
711 | /*****************************************************************************/ |
623 | |
712 | |
624 | #if EV_AVOID_STDIO |
713 | #if EV_AVOID_STDIO |
625 | static void noinline |
714 | static void noinline ecb_cold |
626 | ev_printerr (const char *msg) |
715 | ev_printerr (const char *msg) |
627 | { |
716 | { |
628 | write (STDERR_FILENO, msg, strlen (msg)); |
717 | write (STDERR_FILENO, msg, strlen (msg)); |
629 | } |
718 | } |
630 | #endif |
719 | #endif |
631 | |
720 | |
632 | static void (*syserr_cb)(const char *msg); |
721 | static void (*syserr_cb)(const char *msg); |
633 | |
722 | |
634 | void |
723 | void ecb_cold |
635 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
724 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
636 | { |
725 | { |
637 | syserr_cb = cb; |
726 | syserr_cb = cb; |
638 | } |
727 | } |
639 | |
728 | |
640 | static void noinline |
729 | static void noinline ecb_cold |
641 | ev_syserr (const char *msg) |
730 | ev_syserr (const char *msg) |
642 | { |
731 | { |
643 | if (!msg) |
732 | if (!msg) |
644 | msg = "(libev) system error"; |
733 | msg = "(libev) system error"; |
645 | |
734 | |
… | |
… | |
678 | #endif |
767 | #endif |
679 | } |
768 | } |
680 | |
769 | |
681 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
770 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
682 | |
771 | |
683 | void |
772 | void ecb_cold |
684 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
773 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
685 | { |
774 | { |
686 | alloc = cb; |
775 | alloc = cb; |
687 | } |
776 | } |
688 | |
777 | |
… | |
… | |
897 | } |
986 | } |
898 | |
987 | |
899 | return ncur; |
988 | return ncur; |
900 | } |
989 | } |
901 | |
990 | |
902 | static noinline void * |
991 | static void * noinline ecb_cold |
903 | array_realloc (int elem, void *base, int *cur, int cnt) |
992 | array_realloc (int elem, void *base, int *cur, int cnt) |
904 | { |
993 | { |
905 | *cur = array_nextsize (elem, *cur, cnt); |
994 | *cur = array_nextsize (elem, *cur, cnt); |
906 | return ev_realloc (base, elem * *cur); |
995 | return ev_realloc (base, elem * *cur); |
907 | } |
996 | } |
… | |
… | |
910 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
999 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
911 | |
1000 | |
912 | #define array_needsize(type,base,cur,cnt,init) \ |
1001 | #define array_needsize(type,base,cur,cnt,init) \ |
913 | if (expect_false ((cnt) > (cur))) \ |
1002 | if (expect_false ((cnt) > (cur))) \ |
914 | { \ |
1003 | { \ |
915 | int ocur_ = (cur); \ |
1004 | int ecb_unused ocur_ = (cur); \ |
916 | (base) = (type *)array_realloc \ |
1005 | (base) = (type *)array_realloc \ |
917 | (sizeof (type), (base), &(cur), (cnt)); \ |
1006 | (sizeof (type), (base), &(cur), (cnt)); \ |
918 | init ((base) + (ocur_), (cur) - ocur_); \ |
1007 | init ((base) + (ocur_), (cur) - ocur_); \ |
919 | } |
1008 | } |
920 | |
1009 | |
… | |
… | |
1090 | fdchanges [fdchangecnt - 1] = fd; |
1179 | fdchanges [fdchangecnt - 1] = fd; |
1091 | } |
1180 | } |
1092 | } |
1181 | } |
1093 | |
1182 | |
1094 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
1183 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
1095 | inline_speed void |
1184 | inline_speed void ecb_cold |
1096 | fd_kill (EV_P_ int fd) |
1185 | fd_kill (EV_P_ int fd) |
1097 | { |
1186 | { |
1098 | ev_io *w; |
1187 | ev_io *w; |
1099 | |
1188 | |
1100 | while ((w = (ev_io *)anfds [fd].head)) |
1189 | while ((w = (ev_io *)anfds [fd].head)) |
… | |
… | |
1103 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
1192 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
1104 | } |
1193 | } |
1105 | } |
1194 | } |
1106 | |
1195 | |
1107 | /* check whether the given fd is actually valid, for error recovery */ |
1196 | /* check whether the given fd is actually valid, for error recovery */ |
1108 | inline_size int |
1197 | inline_size int ecb_cold |
1109 | fd_valid (int fd) |
1198 | fd_valid (int fd) |
1110 | { |
1199 | { |
1111 | #ifdef _WIN32 |
1200 | #ifdef _WIN32 |
1112 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
1201 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
1113 | #else |
1202 | #else |
1114 | return fcntl (fd, F_GETFD) != -1; |
1203 | return fcntl (fd, F_GETFD) != -1; |
1115 | #endif |
1204 | #endif |
1116 | } |
1205 | } |
1117 | |
1206 | |
1118 | /* called on EBADF to verify fds */ |
1207 | /* called on EBADF to verify fds */ |
1119 | static void noinline |
1208 | static void noinline ecb_cold |
1120 | fd_ebadf (EV_P) |
1209 | fd_ebadf (EV_P) |
1121 | { |
1210 | { |
1122 | int fd; |
1211 | int fd; |
1123 | |
1212 | |
1124 | for (fd = 0; fd < anfdmax; ++fd) |
1213 | for (fd = 0; fd < anfdmax; ++fd) |
… | |
… | |
1126 | if (!fd_valid (fd) && errno == EBADF) |
1215 | if (!fd_valid (fd) && errno == EBADF) |
1127 | fd_kill (EV_A_ fd); |
1216 | fd_kill (EV_A_ fd); |
1128 | } |
1217 | } |
1129 | |
1218 | |
1130 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
1219 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
1131 | static void noinline |
1220 | static void noinline ecb_cold |
1132 | fd_enomem (EV_P) |
1221 | fd_enomem (EV_P) |
1133 | { |
1222 | { |
1134 | int fd; |
1223 | int fd; |
1135 | |
1224 | |
1136 | for (fd = anfdmax; fd--; ) |
1225 | for (fd = anfdmax; fd--; ) |
… | |
… | |
1331 | |
1420 | |
1332 | /*****************************************************************************/ |
1421 | /*****************************************************************************/ |
1333 | |
1422 | |
1334 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1423 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1335 | |
1424 | |
1336 | static void noinline |
1425 | static void noinline ecb_cold |
1337 | evpipe_init (EV_P) |
1426 | evpipe_init (EV_P) |
1338 | { |
1427 | { |
1339 | if (!ev_is_active (&pipe_w)) |
1428 | if (!ev_is_active (&pipe_w)) |
1340 | { |
1429 | { |
1341 | # if EV_USE_EVENTFD |
1430 | # if EV_USE_EVENTFD |
… | |
… | |
1363 | ev_io_start (EV_A_ &pipe_w); |
1452 | ev_io_start (EV_A_ &pipe_w); |
1364 | ev_unref (EV_A); /* watcher should not keep loop alive */ |
1453 | ev_unref (EV_A); /* watcher should not keep loop alive */ |
1365 | } |
1454 | } |
1366 | } |
1455 | } |
1367 | |
1456 | |
1368 | inline_size void |
1457 | inline_speed void |
1369 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1458 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1370 | { |
1459 | { |
1371 | if (!*flag) |
1460 | if (expect_true (*flag)) |
1372 | { |
1461 | /*return*//*D*/; |
|
|
1462 | |
1373 | *flag = 1; |
1463 | *flag = 1; |
1374 | |
1464 | |
|
|
1465 | ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */ |
|
|
1466 | |
1375 | pipe_write_skipped = 1; |
1467 | pipe_write_skipped = 1; |
1376 | |
1468 | |
|
|
1469 | ECB_MEMORY_FENCE; /* make sure pipe_write_skipped is visible before we check pipe_write_wanted */ |
|
|
1470 | |
1377 | if (pipe_write_wanted) |
1471 | if (pipe_write_wanted) |
|
|
1472 | { |
|
|
1473 | int old_errno; |
|
|
1474 | |
|
|
1475 | pipe_write_skipped = 0; /* just an optimsiation, no fence needed */ |
|
|
1476 | |
|
|
1477 | old_errno = errno; /* save errno because write will clobber it */ |
|
|
1478 | |
|
|
1479 | #if EV_USE_EVENTFD |
|
|
1480 | if (evfd >= 0) |
1378 | { |
1481 | { |
1379 | int old_errno = errno; /* save errno because write will clobber it */ |
|
|
1380 | char dummy; |
|
|
1381 | |
|
|
1382 | pipe_write_skipped = 0; |
|
|
1383 | |
|
|
1384 | #if EV_USE_EVENTFD |
|
|
1385 | if (evfd >= 0) |
|
|
1386 | { |
|
|
1387 | uint64_t counter = 1; |
1482 | uint64_t counter = 1; |
1388 | write (evfd, &counter, sizeof (uint64_t)); |
1483 | write (evfd, &counter, sizeof (uint64_t)); |
1389 | } |
|
|
1390 | else |
|
|
1391 | #endif |
|
|
1392 | { |
|
|
1393 | /* win32 people keep sending patches that change this write() to send() */ |
|
|
1394 | /* and then run away. but send() is wrong, it wants a socket handle on win32 */ |
|
|
1395 | /* so when you think this write should be a send instead, please find out */ |
|
|
1396 | /* where your send() is from - it's definitely not the microsoft send, and */ |
|
|
1397 | /* tell me. thank you. */ |
|
|
1398 | write (evpipe [1], &dummy, 1); |
|
|
1399 | } |
|
|
1400 | |
|
|
1401 | errno = old_errno; |
|
|
1402 | } |
1484 | } |
|
|
1485 | else |
|
|
1486 | #endif |
|
|
1487 | { |
|
|
1488 | /* win32 people keep sending patches that change this write() to send() */ |
|
|
1489 | /* and then run away. but send() is wrong, it wants a socket handle on win32 */ |
|
|
1490 | /* so when you think this write should be a send instead, please find out */ |
|
|
1491 | /* where your send() is from - it's definitely not the microsoft send, and */ |
|
|
1492 | /* tell me. thank you. */ |
|
|
1493 | write (evpipe [1], &(evpipe [1]), 1); |
|
|
1494 | } |
|
|
1495 | |
|
|
1496 | errno = old_errno; |
1403 | } |
1497 | } |
1404 | } |
1498 | } |
1405 | |
1499 | |
1406 | /* called whenever the libev signal pipe */ |
1500 | /* called whenever the libev signal pipe */ |
1407 | /* got some events (signal, async) */ |
1501 | /* got some events (signal, async) */ |
… | |
… | |
1465 | |
1559 | |
1466 | if (!EV_A) |
1560 | if (!EV_A) |
1467 | return; |
1561 | return; |
1468 | #endif |
1562 | #endif |
1469 | |
1563 | |
1470 | evpipe_init (EV_A); |
1564 | if (!ev_active (&pipe_w)) |
|
|
1565 | return; |
1471 | |
1566 | |
1472 | signals [signum - 1].pending = 1; |
1567 | signals [signum - 1].pending = 1; |
1473 | evpipe_write (EV_A_ &sig_pending); |
1568 | evpipe_write (EV_A_ &sig_pending); |
1474 | } |
1569 | } |
1475 | |
1570 | |
… | |
… | |
1607 | #endif |
1702 | #endif |
1608 | #if EV_USE_SELECT |
1703 | #if EV_USE_SELECT |
1609 | # include "ev_select.c" |
1704 | # include "ev_select.c" |
1610 | #endif |
1705 | #endif |
1611 | |
1706 | |
1612 | int |
1707 | int ecb_cold |
1613 | ev_version_major (void) |
1708 | ev_version_major (void) |
1614 | { |
1709 | { |
1615 | return EV_VERSION_MAJOR; |
1710 | return EV_VERSION_MAJOR; |
1616 | } |
1711 | } |
1617 | |
1712 | |
1618 | int |
1713 | int ecb_cold |
1619 | ev_version_minor (void) |
1714 | ev_version_minor (void) |
1620 | { |
1715 | { |
1621 | return EV_VERSION_MINOR; |
1716 | return EV_VERSION_MINOR; |
1622 | } |
1717 | } |
1623 | |
1718 | |
1624 | /* return true if we are running with elevated privileges and should ignore env variables */ |
1719 | /* return true if we are running with elevated privileges and should ignore env variables */ |
1625 | int inline_size |
1720 | int inline_size ecb_cold |
1626 | enable_secure (void) |
1721 | enable_secure (void) |
1627 | { |
1722 | { |
1628 | #ifdef _WIN32 |
1723 | #ifdef _WIN32 |
1629 | return 0; |
1724 | return 0; |
1630 | #else |
1725 | #else |
1631 | return getuid () != geteuid () |
1726 | return getuid () != geteuid () |
1632 | || getgid () != getegid (); |
1727 | || getgid () != getegid (); |
1633 | #endif |
1728 | #endif |
1634 | } |
1729 | } |
1635 | |
1730 | |
1636 | unsigned int |
1731 | unsigned int ecb_cold |
1637 | ev_supported_backends (void) |
1732 | ev_supported_backends (void) |
1638 | { |
1733 | { |
1639 | unsigned int flags = 0; |
1734 | unsigned int flags = 0; |
1640 | |
1735 | |
1641 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
1736 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
… | |
… | |
1645 | if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; |
1740 | if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; |
1646 | |
1741 | |
1647 | return flags; |
1742 | return flags; |
1648 | } |
1743 | } |
1649 | |
1744 | |
1650 | unsigned int |
1745 | unsigned int ecb_cold |
1651 | ev_recommended_backends (void) |
1746 | ev_recommended_backends (void) |
1652 | { |
1747 | { |
1653 | unsigned int flags = ev_supported_backends (); |
1748 | unsigned int flags = ev_supported_backends (); |
1654 | |
1749 | |
1655 | #ifndef __NetBSD__ |
1750 | #ifndef __NetBSD__ |
… | |
… | |
1667 | #endif |
1762 | #endif |
1668 | |
1763 | |
1669 | return flags; |
1764 | return flags; |
1670 | } |
1765 | } |
1671 | |
1766 | |
1672 | unsigned int |
1767 | unsigned int ecb_cold |
1673 | ev_embeddable_backends (void) |
1768 | ev_embeddable_backends (void) |
1674 | { |
1769 | { |
1675 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
1770 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
1676 | |
1771 | |
1677 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
1772 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
… | |
… | |
1722 | ev_userdata (EV_P) |
1817 | ev_userdata (EV_P) |
1723 | { |
1818 | { |
1724 | return userdata; |
1819 | return userdata; |
1725 | } |
1820 | } |
1726 | |
1821 | |
|
|
1822 | void |
1727 | void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) |
1823 | ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) |
1728 | { |
1824 | { |
1729 | invoke_cb = invoke_pending_cb; |
1825 | invoke_cb = invoke_pending_cb; |
1730 | } |
1826 | } |
1731 | |
1827 | |
|
|
1828 | void |
1732 | void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) |
1829 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) |
1733 | { |
1830 | { |
1734 | release_cb = release; |
1831 | release_cb = release; |
1735 | acquire_cb = acquire; |
1832 | acquire_cb = acquire; |
1736 | } |
1833 | } |
1737 | #endif |
1834 | #endif |
1738 | |
1835 | |
1739 | /* initialise a loop structure, must be zero-initialised */ |
1836 | /* initialise a loop structure, must be zero-initialised */ |
1740 | static void noinline |
1837 | static void noinline ecb_cold |
1741 | loop_init (EV_P_ unsigned int flags) |
1838 | loop_init (EV_P_ unsigned int flags) |
1742 | { |
1839 | { |
1743 | if (!backend) |
1840 | if (!backend) |
1744 | { |
1841 | { |
1745 | origflags = flags; |
1842 | origflags = flags; |
… | |
… | |
1830 | #endif |
1927 | #endif |
1831 | } |
1928 | } |
1832 | } |
1929 | } |
1833 | |
1930 | |
1834 | /* free up a loop structure */ |
1931 | /* free up a loop structure */ |
1835 | void |
1932 | void ecb_cold |
1836 | ev_loop_destroy (EV_P) |
1933 | ev_loop_destroy (EV_P) |
1837 | { |
1934 | { |
1838 | int i; |
1935 | int i; |
1839 | |
1936 | |
1840 | #if EV_MULTIPLICITY |
1937 | #if EV_MULTIPLICITY |
… | |
… | |
1998 | postfork = 0; |
2095 | postfork = 0; |
1999 | } |
2096 | } |
2000 | |
2097 | |
2001 | #if EV_MULTIPLICITY |
2098 | #if EV_MULTIPLICITY |
2002 | |
2099 | |
2003 | struct ev_loop * |
2100 | struct ev_loop * ecb_cold |
2004 | ev_loop_new (unsigned int flags) |
2101 | ev_loop_new (unsigned int flags) |
2005 | { |
2102 | { |
2006 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2103 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2007 | |
2104 | |
2008 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2105 | memset (EV_A, 0, sizeof (struct ev_loop)); |
… | |
… | |
2016 | } |
2113 | } |
2017 | |
2114 | |
2018 | #endif /* multiplicity */ |
2115 | #endif /* multiplicity */ |
2019 | |
2116 | |
2020 | #if EV_VERIFY |
2117 | #if EV_VERIFY |
2021 | static void noinline |
2118 | static void noinline ecb_cold |
2022 | verify_watcher (EV_P_ W w) |
2119 | verify_watcher (EV_P_ W w) |
2023 | { |
2120 | { |
2024 | assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
2121 | assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
2025 | |
2122 | |
2026 | if (w->pending) |
2123 | if (w->pending) |
2027 | assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); |
2124 | assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); |
2028 | } |
2125 | } |
2029 | |
2126 | |
2030 | static void noinline |
2127 | static void noinline ecb_cold |
2031 | verify_heap (EV_P_ ANHE *heap, int N) |
2128 | verify_heap (EV_P_ ANHE *heap, int N) |
2032 | { |
2129 | { |
2033 | int i; |
2130 | int i; |
2034 | |
2131 | |
2035 | for (i = HEAP0; i < N + HEAP0; ++i) |
2132 | for (i = HEAP0; i < N + HEAP0; ++i) |
… | |
… | |
2040 | |
2137 | |
2041 | verify_watcher (EV_A_ (W)ANHE_w (heap [i])); |
2138 | verify_watcher (EV_A_ (W)ANHE_w (heap [i])); |
2042 | } |
2139 | } |
2043 | } |
2140 | } |
2044 | |
2141 | |
2045 | static void noinline |
2142 | static void noinline ecb_cold |
2046 | array_verify (EV_P_ W *ws, int cnt) |
2143 | array_verify (EV_P_ W *ws, int cnt) |
2047 | { |
2144 | { |
2048 | while (cnt--) |
2145 | while (cnt--) |
2049 | { |
2146 | { |
2050 | assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1)); |
2147 | assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1)); |
… | |
… | |
2052 | } |
2149 | } |
2053 | } |
2150 | } |
2054 | #endif |
2151 | #endif |
2055 | |
2152 | |
2056 | #if EV_FEATURE_API |
2153 | #if EV_FEATURE_API |
2057 | void |
2154 | void ecb_cold |
2058 | ev_verify (EV_P) |
2155 | ev_verify (EV_P) |
2059 | { |
2156 | { |
2060 | #if EV_VERIFY |
2157 | #if EV_VERIFY |
2061 | int i; |
2158 | int i; |
2062 | WL w; |
2159 | WL w; |
… | |
… | |
2128 | #endif |
2225 | #endif |
2129 | } |
2226 | } |
2130 | #endif |
2227 | #endif |
2131 | |
2228 | |
2132 | #if EV_MULTIPLICITY |
2229 | #if EV_MULTIPLICITY |
2133 | struct ev_loop * |
2230 | struct ev_loop * ecb_cold |
2134 | #else |
2231 | #else |
2135 | int |
2232 | int |
2136 | #endif |
2233 | #endif |
2137 | ev_default_loop (unsigned int flags) |
2234 | ev_default_loop (unsigned int flags) |
2138 | { |
2235 | { |
… | |
… | |
2337 | } |
2434 | } |
2338 | } |
2435 | } |
2339 | |
2436 | |
2340 | /* simply recalculate all periodics */ |
2437 | /* simply recalculate all periodics */ |
2341 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
2438 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
2342 | static void noinline |
2439 | static void noinline ecb_cold |
2343 | periodics_reschedule (EV_P) |
2440 | periodics_reschedule (EV_P) |
2344 | { |
2441 | { |
2345 | int i; |
2442 | int i; |
2346 | |
2443 | |
2347 | /* adjust periodics after time jump */ |
2444 | /* adjust periodics after time jump */ |
… | |
… | |
2360 | reheap (periodics, periodiccnt); |
2457 | reheap (periodics, periodiccnt); |
2361 | } |
2458 | } |
2362 | #endif |
2459 | #endif |
2363 | |
2460 | |
2364 | /* adjust all timers by a given offset */ |
2461 | /* adjust all timers by a given offset */ |
2365 | static void noinline |
2462 | static void noinline ecb_cold |
2366 | timers_reschedule (EV_P_ ev_tstamp adjust) |
2463 | timers_reschedule (EV_P_ ev_tstamp adjust) |
2367 | { |
2464 | { |
2368 | int i; |
2465 | int i; |
2369 | |
2466 | |
2370 | for (i = 0; i < timercnt; ++i) |
2467 | for (i = 0; i < timercnt; ++i) |
… | |
… | |
2515 | time_update (EV_A_ 1e100); |
2612 | time_update (EV_A_ 1e100); |
2516 | |
2613 | |
2517 | /* from now on, we want a pipe-wake-up */ |
2614 | /* from now on, we want a pipe-wake-up */ |
2518 | pipe_write_wanted = 1; |
2615 | pipe_write_wanted = 1; |
2519 | |
2616 | |
|
|
2617 | ECB_MEMORY_FENCE; /* amke sure pipe_write_wanted is visible before we check for potential skips */ |
|
|
2618 | |
2520 | if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped))) |
2619 | if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped))) |
2521 | { |
2620 | { |
2522 | waittime = MAX_BLOCKTIME; |
2621 | waittime = MAX_BLOCKTIME; |
2523 | |
2622 | |
2524 | if (timercnt) |
2623 | if (timercnt) |
… | |
… | |
2565 | #endif |
2664 | #endif |
2566 | assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */ |
2665 | assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */ |
2567 | backend_poll (EV_A_ waittime); |
2666 | backend_poll (EV_A_ waittime); |
2568 | assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ |
2667 | assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ |
2569 | |
2668 | |
2570 | pipe_write_wanted = 0; |
2669 | pipe_write_wanted = 0; /* just an optimsiation, no fence needed */ |
2571 | |
2670 | |
2572 | if (pipe_write_skipped) |
2671 | if (pipe_write_skipped) |
2573 | { |
2672 | { |
2574 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
2673 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
2575 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
2674 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
… | |
… | |
3236 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
3335 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
3237 | ofs += sizeof (struct inotify_event) + ev->len; |
3336 | ofs += sizeof (struct inotify_event) + ev->len; |
3238 | } |
3337 | } |
3239 | } |
3338 | } |
3240 | |
3339 | |
3241 | inline_size void |
3340 | inline_size void ecb_cold |
3242 | ev_check_2625 (EV_P) |
3341 | ev_check_2625 (EV_P) |
3243 | { |
3342 | { |
3244 | /* kernels < 2.6.25 are borked |
3343 | /* kernels < 2.6.25 are borked |
3245 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
3344 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
3246 | */ |
3345 | */ |
… | |
… | |
3871 | } |
3970 | } |
3872 | |
3971 | |
3873 | /*****************************************************************************/ |
3972 | /*****************************************************************************/ |
3874 | |
3973 | |
3875 | #if EV_WALK_ENABLE |
3974 | #if EV_WALK_ENABLE |
3876 | void |
3975 | void ecb_cold |
3877 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) |
3976 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) |
3878 | { |
3977 | { |
3879 | int i, j; |
3978 | int i, j; |
3880 | ev_watcher_list *wl, *wn; |
3979 | ev_watcher_list *wl, *wn; |
3881 | |
3980 | |