… | |
… | |
198 | # define inline_speed static inline |
198 | # define inline_speed static inline |
199 | # endif |
199 | # endif |
200 | #else |
200 | #else |
201 | # define expect(expr,value) (expr) |
201 | # define expect(expr,value) (expr) |
202 | # define inline_speed static |
202 | # define inline_speed static |
203 | # define inline_minimal static |
203 | # define inline_size static |
204 | # define noinline |
204 | # define noinline |
205 | #endif |
205 | #endif |
206 | |
206 | |
207 | #define expect_false(expr) expect ((expr) != 0, 0) |
207 | #define expect_false(expr) expect ((expr) != 0, 0) |
208 | #define expect_true(expr) expect ((expr) != 0, 1) |
208 | #define expect_true(expr) expect ((expr) != 0, 1) |
… | |
… | |
225 | |
225 | |
226 | /*****************************************************************************/ |
226 | /*****************************************************************************/ |
227 | |
227 | |
228 | static void (*syserr_cb)(const char *msg); |
228 | static void (*syserr_cb)(const char *msg); |
229 | |
229 | |
|
|
230 | void |
230 | void ev_set_syserr_cb (void (*cb)(const char *msg)) |
231 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
231 | { |
232 | { |
232 | syserr_cb = cb; |
233 | syserr_cb = cb; |
233 | } |
234 | } |
234 | |
235 | |
235 | static void |
236 | static void noinline |
236 | syserr (const char *msg) |
237 | syserr (const char *msg) |
237 | { |
238 | { |
238 | if (!msg) |
239 | if (!msg) |
239 | msg = "(libev) system error"; |
240 | msg = "(libev) system error"; |
240 | |
241 | |
… | |
… | |
247 | } |
248 | } |
248 | } |
249 | } |
249 | |
250 | |
250 | static void *(*alloc)(void *ptr, long size); |
251 | static void *(*alloc)(void *ptr, long size); |
251 | |
252 | |
|
|
253 | void |
252 | void ev_set_allocator (void *(*cb)(void *ptr, long size)) |
254 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
253 | { |
255 | { |
254 | alloc = cb; |
256 | alloc = cb; |
255 | } |
257 | } |
256 | |
258 | |
257 | static void * |
259 | static void * |
… | |
… | |
315 | |
317 | |
316 | #endif |
318 | #endif |
317 | |
319 | |
318 | /*****************************************************************************/ |
320 | /*****************************************************************************/ |
319 | |
321 | |
320 | ev_tstamp noinline |
322 | ev_tstamp |
321 | ev_time (void) |
323 | ev_time (void) |
322 | { |
324 | { |
323 | #if EV_USE_REALTIME |
325 | #if EV_USE_REALTIME |
324 | struct timespec ts; |
326 | struct timespec ts; |
325 | clock_gettime (CLOCK_REALTIME, &ts); |
327 | clock_gettime (CLOCK_REALTIME, &ts); |
… | |
… | |
382 | #define array_free(stem, idx) \ |
384 | #define array_free(stem, idx) \ |
383 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
385 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
384 | |
386 | |
385 | /*****************************************************************************/ |
387 | /*****************************************************************************/ |
386 | |
388 | |
387 | void inline_size |
|
|
388 | anfds_init (ANFD *base, int count) |
|
|
389 | { |
|
|
390 | while (count--) |
|
|
391 | { |
|
|
392 | base->head = 0; |
|
|
393 | base->events = EV_NONE; |
|
|
394 | base->reify = 0; |
|
|
395 | |
|
|
396 | ++base; |
|
|
397 | } |
|
|
398 | } |
|
|
399 | |
|
|
400 | void noinline |
389 | void noinline |
401 | ev_feed_event (EV_P_ void *w, int revents) |
390 | ev_feed_event (EV_P_ void *w, int revents) |
402 | { |
391 | { |
403 | W w_ = (W)w; |
392 | W w_ = (W)w; |
404 | |
393 | |
… | |
… | |
412 | array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2); |
401 | array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2); |
413 | pendings [ABSPRI (w_)][w_->pending - 1].w = w_; |
402 | pendings [ABSPRI (w_)][w_->pending - 1].w = w_; |
414 | pendings [ABSPRI (w_)][w_->pending - 1].events = revents; |
403 | pendings [ABSPRI (w_)][w_->pending - 1].events = revents; |
415 | } |
404 | } |
416 | |
405 | |
417 | static void |
406 | void inline_size |
418 | queue_events (EV_P_ W *events, int eventcnt, int type) |
407 | queue_events (EV_P_ W *events, int eventcnt, int type) |
419 | { |
408 | { |
420 | int i; |
409 | int i; |
421 | |
410 | |
422 | for (i = 0; i < eventcnt; ++i) |
411 | for (i = 0; i < eventcnt; ++i) |
423 | ev_feed_event (EV_A_ events [i], type); |
412 | ev_feed_event (EV_A_ events [i], type); |
424 | } |
413 | } |
425 | |
414 | |
|
|
415 | /*****************************************************************************/ |
|
|
416 | |
|
|
417 | void inline_size |
|
|
418 | anfds_init (ANFD *base, int count) |
|
|
419 | { |
|
|
420 | while (count--) |
|
|
421 | { |
|
|
422 | base->head = 0; |
|
|
423 | base->events = EV_NONE; |
|
|
424 | base->reify = 0; |
|
|
425 | |
|
|
426 | ++base; |
|
|
427 | } |
|
|
428 | } |
|
|
429 | |
426 | void inline_speed |
430 | void inline_speed |
427 | fd_event (EV_P_ int fd, int revents) |
431 | fd_event (EV_P_ int fd, int revents) |
428 | { |
432 | { |
429 | ANFD *anfd = anfds + fd; |
433 | ANFD *anfd = anfds + fd; |
430 | ev_io *w; |
434 | ev_io *w; |
… | |
… | |
441 | void |
445 | void |
442 | ev_feed_fd_event (EV_P_ int fd, int revents) |
446 | ev_feed_fd_event (EV_P_ int fd, int revents) |
443 | { |
447 | { |
444 | fd_event (EV_A_ fd, revents); |
448 | fd_event (EV_A_ fd, revents); |
445 | } |
449 | } |
446 | |
|
|
447 | /*****************************************************************************/ |
|
|
448 | |
450 | |
449 | void inline_size |
451 | void inline_size |
450 | fd_reify (EV_P) |
452 | fd_reify (EV_P) |
451 | { |
453 | { |
452 | int i; |
454 | int i; |
… | |
… | |
712 | static ev_child *childs [PID_HASHSIZE]; |
714 | static ev_child *childs [PID_HASHSIZE]; |
713 | |
715 | |
714 | #ifndef _WIN32 |
716 | #ifndef _WIN32 |
715 | |
717 | |
716 | static ev_signal childev; |
718 | static ev_signal childev; |
717 | |
|
|
718 | #ifndef WCONTINUED |
|
|
719 | # define WCONTINUED 0 |
|
|
720 | #endif |
|
|
721 | |
719 | |
722 | void inline_speed |
720 | void inline_speed |
723 | child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) |
721 | child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) |
724 | { |
722 | { |
725 | ev_child *w; |
723 | ev_child *w; |
… | |
… | |
732 | w->rstatus = status; |
730 | w->rstatus = status; |
733 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
731 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
734 | } |
732 | } |
735 | } |
733 | } |
736 | |
734 | |
|
|
735 | #ifndef WCONTINUED |
|
|
736 | # define WCONTINUED 0 |
|
|
737 | #endif |
|
|
738 | |
737 | static void |
739 | static void |
738 | childcb (EV_P_ ev_signal *sw, int revents) |
740 | childcb (EV_P_ ev_signal *sw, int revents) |
739 | { |
741 | { |
740 | int pid, status; |
742 | int pid, status; |
741 | |
743 | |
|
|
744 | /* some systems define WCONTINUED but then fail to support it (linux 2.4) */ |
742 | if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
745 | if (0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
743 | { |
746 | if (!WCONTINUED |
|
|
747 | || errno != EINVAL |
|
|
748 | || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED))) |
|
|
749 | return; |
|
|
750 | |
744 | /* make sure we are called again until all childs have been reaped */ |
751 | /* make sure we are called again until all childs have been reaped */ |
745 | /* we need to do it this way so that the callback gets called before we continue */ |
752 | /* we need to do it this way so that the callback gets called before we continue */ |
746 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
753 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
747 | |
754 | |
748 | child_reap (EV_A_ sw, pid, pid, status); |
755 | child_reap (EV_A_ sw, pid, pid, status); |
749 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
756 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
750 | } |
|
|
751 | } |
757 | } |
752 | |
758 | |
753 | #endif |
759 | #endif |
754 | |
760 | |
755 | /*****************************************************************************/ |
761 | /*****************************************************************************/ |
… | |
… | |
1270 | ? EVUNLOOP_ONE |
1276 | ? EVUNLOOP_ONE |
1271 | : EVUNLOOP_CANCEL; |
1277 | : EVUNLOOP_CANCEL; |
1272 | |
1278 | |
1273 | while (activecnt) |
1279 | while (activecnt) |
1274 | { |
1280 | { |
|
|
1281 | /* we might have forked, so reify kernel state if necessary */ |
|
|
1282 | #if EV_FORK_ENABLE |
|
|
1283 | if (expect_false (postfork)) |
|
|
1284 | if (forkcnt) |
|
|
1285 | { |
|
|
1286 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
|
|
1287 | call_pending (EV_A); |
|
|
1288 | } |
|
|
1289 | #endif |
|
|
1290 | |
1275 | /* queue check watchers (and execute them) */ |
1291 | /* queue check watchers (and execute them) */ |
1276 | if (expect_false (preparecnt)) |
1292 | if (expect_false (preparecnt)) |
1277 | { |
1293 | { |
1278 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1294 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1279 | call_pending (EV_A); |
1295 | call_pending (EV_A); |
… | |
… | |
1552 | ev_periodic_stop (EV_A_ w); |
1568 | ev_periodic_stop (EV_A_ w); |
1553 | ev_periodic_start (EV_A_ w); |
1569 | ev_periodic_start (EV_A_ w); |
1554 | } |
1570 | } |
1555 | #endif |
1571 | #endif |
1556 | |
1572 | |
1557 | void |
|
|
1558 | ev_idle_start (EV_P_ ev_idle *w) |
|
|
1559 | { |
|
|
1560 | if (expect_false (ev_is_active (w))) |
|
|
1561 | return; |
|
|
1562 | |
|
|
1563 | ev_start (EV_A_ (W)w, ++idlecnt); |
|
|
1564 | array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
|
|
1565 | idles [idlecnt - 1] = w; |
|
|
1566 | } |
|
|
1567 | |
|
|
1568 | void |
|
|
1569 | ev_idle_stop (EV_P_ ev_idle *w) |
|
|
1570 | { |
|
|
1571 | ev_clear_pending (EV_A_ (W)w); |
|
|
1572 | if (expect_false (!ev_is_active (w))) |
|
|
1573 | return; |
|
|
1574 | |
|
|
1575 | { |
|
|
1576 | int active = ((W)w)->active; |
|
|
1577 | idles [active - 1] = idles [--idlecnt]; |
|
|
1578 | ((W)idles [active - 1])->active = active; |
|
|
1579 | } |
|
|
1580 | |
|
|
1581 | ev_stop (EV_A_ (W)w); |
|
|
1582 | } |
|
|
1583 | |
|
|
1584 | void |
|
|
1585 | ev_prepare_start (EV_P_ ev_prepare *w) |
|
|
1586 | { |
|
|
1587 | if (expect_false (ev_is_active (w))) |
|
|
1588 | return; |
|
|
1589 | |
|
|
1590 | ev_start (EV_A_ (W)w, ++preparecnt); |
|
|
1591 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
|
|
1592 | prepares [preparecnt - 1] = w; |
|
|
1593 | } |
|
|
1594 | |
|
|
1595 | void |
|
|
1596 | ev_prepare_stop (EV_P_ ev_prepare *w) |
|
|
1597 | { |
|
|
1598 | ev_clear_pending (EV_A_ (W)w); |
|
|
1599 | if (expect_false (!ev_is_active (w))) |
|
|
1600 | return; |
|
|
1601 | |
|
|
1602 | { |
|
|
1603 | int active = ((W)w)->active; |
|
|
1604 | prepares [active - 1] = prepares [--preparecnt]; |
|
|
1605 | ((W)prepares [active - 1])->active = active; |
|
|
1606 | } |
|
|
1607 | |
|
|
1608 | ev_stop (EV_A_ (W)w); |
|
|
1609 | } |
|
|
1610 | |
|
|
1611 | void |
|
|
1612 | ev_check_start (EV_P_ ev_check *w) |
|
|
1613 | { |
|
|
1614 | if (expect_false (ev_is_active (w))) |
|
|
1615 | return; |
|
|
1616 | |
|
|
1617 | ev_start (EV_A_ (W)w, ++checkcnt); |
|
|
1618 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
|
|
1619 | checks [checkcnt - 1] = w; |
|
|
1620 | } |
|
|
1621 | |
|
|
1622 | void |
|
|
1623 | ev_check_stop (EV_P_ ev_check *w) |
|
|
1624 | { |
|
|
1625 | ev_clear_pending (EV_A_ (W)w); |
|
|
1626 | if (expect_false (!ev_is_active (w))) |
|
|
1627 | return; |
|
|
1628 | |
|
|
1629 | { |
|
|
1630 | int active = ((W)w)->active; |
|
|
1631 | checks [active - 1] = checks [--checkcnt]; |
|
|
1632 | ((W)checks [active - 1])->active = active; |
|
|
1633 | } |
|
|
1634 | |
|
|
1635 | ev_stop (EV_A_ (W)w); |
|
|
1636 | } |
|
|
1637 | |
|
|
1638 | #ifndef SA_RESTART |
1573 | #ifndef SA_RESTART |
1639 | # define SA_RESTART 0 |
1574 | # define SA_RESTART 0 |
1640 | #endif |
1575 | #endif |
1641 | |
1576 | |
1642 | void |
1577 | void |
… | |
… | |
1704 | |
1639 | |
1705 | wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1640 | wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1706 | ev_stop (EV_A_ (W)w); |
1641 | ev_stop (EV_A_ (W)w); |
1707 | } |
1642 | } |
1708 | |
1643 | |
|
|
1644 | #if EV_STAT_ENABLE |
|
|
1645 | |
|
|
1646 | # ifdef _WIN32 |
|
|
1647 | # undef lstat |
|
|
1648 | # define lstat(a,b) _stati64 (a,b) |
|
|
1649 | # endif |
|
|
1650 | |
|
|
1651 | #define DEF_STAT_INTERVAL 5.0074891 |
|
|
1652 | #define MIN_STAT_INTERVAL 0.1074891 |
|
|
1653 | |
|
|
1654 | void |
|
|
1655 | ev_stat_stat (EV_P_ ev_stat *w) |
|
|
1656 | { |
|
|
1657 | if (lstat (w->path, &w->attr) < 0) |
|
|
1658 | w->attr.st_nlink = 0; |
|
|
1659 | else if (!w->attr.st_nlink) |
|
|
1660 | w->attr.st_nlink = 1; |
|
|
1661 | } |
|
|
1662 | |
|
|
1663 | static void |
|
|
1664 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
|
|
1665 | { |
|
|
1666 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
|
|
1667 | |
|
|
1668 | /* we copy this here each the time so that */ |
|
|
1669 | /* prev has the old value when the callback gets invoked */ |
|
|
1670 | w->prev = w->attr; |
|
|
1671 | ev_stat_stat (EV_A_ w); |
|
|
1672 | |
|
|
1673 | if (memcmp (&w->prev, &w->attr, sizeof (ev_statdata))) |
|
|
1674 | ev_feed_event (EV_A_ w, EV_STAT); |
|
|
1675 | } |
|
|
1676 | |
|
|
1677 | void |
|
|
1678 | ev_stat_start (EV_P_ ev_stat *w) |
|
|
1679 | { |
|
|
1680 | if (expect_false (ev_is_active (w))) |
|
|
1681 | return; |
|
|
1682 | |
|
|
1683 | /* since we use memcmp, we need to clear any padding data etc. */ |
|
|
1684 | memset (&w->prev, 0, sizeof (ev_statdata)); |
|
|
1685 | memset (&w->attr, 0, sizeof (ev_statdata)); |
|
|
1686 | |
|
|
1687 | ev_stat_stat (EV_A_ w); |
|
|
1688 | |
|
|
1689 | if (w->interval < MIN_STAT_INTERVAL) |
|
|
1690 | w->interval = w->interval ? MIN_STAT_INTERVAL : DEF_STAT_INTERVAL; |
|
|
1691 | |
|
|
1692 | ev_timer_init (&w->timer, stat_timer_cb, w->interval, w->interval); |
|
|
1693 | ev_set_priority (&w->timer, ev_priority (w)); |
|
|
1694 | ev_timer_start (EV_A_ &w->timer); |
|
|
1695 | |
|
|
1696 | ev_start (EV_A_ (W)w, 1); |
|
|
1697 | } |
|
|
1698 | |
|
|
1699 | void |
|
|
1700 | ev_stat_stop (EV_P_ ev_stat *w) |
|
|
1701 | { |
|
|
1702 | ev_clear_pending (EV_A_ (W)w); |
|
|
1703 | if (expect_false (!ev_is_active (w))) |
|
|
1704 | return; |
|
|
1705 | |
|
|
1706 | ev_timer_stop (EV_A_ &w->timer); |
|
|
1707 | |
|
|
1708 | ev_stop (EV_A_ (W)w); |
|
|
1709 | } |
|
|
1710 | #endif |
|
|
1711 | |
|
|
1712 | void |
|
|
1713 | ev_idle_start (EV_P_ ev_idle *w) |
|
|
1714 | { |
|
|
1715 | if (expect_false (ev_is_active (w))) |
|
|
1716 | return; |
|
|
1717 | |
|
|
1718 | ev_start (EV_A_ (W)w, ++idlecnt); |
|
|
1719 | array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
|
|
1720 | idles [idlecnt - 1] = w; |
|
|
1721 | } |
|
|
1722 | |
|
|
1723 | void |
|
|
1724 | ev_idle_stop (EV_P_ ev_idle *w) |
|
|
1725 | { |
|
|
1726 | ev_clear_pending (EV_A_ (W)w); |
|
|
1727 | if (expect_false (!ev_is_active (w))) |
|
|
1728 | return; |
|
|
1729 | |
|
|
1730 | { |
|
|
1731 | int active = ((W)w)->active; |
|
|
1732 | idles [active - 1] = idles [--idlecnt]; |
|
|
1733 | ((W)idles [active - 1])->active = active; |
|
|
1734 | } |
|
|
1735 | |
|
|
1736 | ev_stop (EV_A_ (W)w); |
|
|
1737 | } |
|
|
1738 | |
|
|
1739 | void |
|
|
1740 | ev_prepare_start (EV_P_ ev_prepare *w) |
|
|
1741 | { |
|
|
1742 | if (expect_false (ev_is_active (w))) |
|
|
1743 | return; |
|
|
1744 | |
|
|
1745 | ev_start (EV_A_ (W)w, ++preparecnt); |
|
|
1746 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
|
|
1747 | prepares [preparecnt - 1] = w; |
|
|
1748 | } |
|
|
1749 | |
|
|
1750 | void |
|
|
1751 | ev_prepare_stop (EV_P_ ev_prepare *w) |
|
|
1752 | { |
|
|
1753 | ev_clear_pending (EV_A_ (W)w); |
|
|
1754 | if (expect_false (!ev_is_active (w))) |
|
|
1755 | return; |
|
|
1756 | |
|
|
1757 | { |
|
|
1758 | int active = ((W)w)->active; |
|
|
1759 | prepares [active - 1] = prepares [--preparecnt]; |
|
|
1760 | ((W)prepares [active - 1])->active = active; |
|
|
1761 | } |
|
|
1762 | |
|
|
1763 | ev_stop (EV_A_ (W)w); |
|
|
1764 | } |
|
|
1765 | |
|
|
1766 | void |
|
|
1767 | ev_check_start (EV_P_ ev_check *w) |
|
|
1768 | { |
|
|
1769 | if (expect_false (ev_is_active (w))) |
|
|
1770 | return; |
|
|
1771 | |
|
|
1772 | ev_start (EV_A_ (W)w, ++checkcnt); |
|
|
1773 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
|
|
1774 | checks [checkcnt - 1] = w; |
|
|
1775 | } |
|
|
1776 | |
|
|
1777 | void |
|
|
1778 | ev_check_stop (EV_P_ ev_check *w) |
|
|
1779 | { |
|
|
1780 | ev_clear_pending (EV_A_ (W)w); |
|
|
1781 | if (expect_false (!ev_is_active (w))) |
|
|
1782 | return; |
|
|
1783 | |
|
|
1784 | { |
|
|
1785 | int active = ((W)w)->active; |
|
|
1786 | checks [active - 1] = checks [--checkcnt]; |
|
|
1787 | ((W)checks [active - 1])->active = active; |
|
|
1788 | } |
|
|
1789 | |
|
|
1790 | ev_stop (EV_A_ (W)w); |
|
|
1791 | } |
|
|
1792 | |
1709 | #if EV_EMBED_ENABLE |
1793 | #if EV_EMBED_ENABLE |
1710 | void noinline |
1794 | void noinline |
1711 | ev_embed_sweep (EV_P_ ev_embed *w) |
1795 | ev_embed_sweep (EV_P_ ev_embed *w) |
1712 | { |
1796 | { |
1713 | ev_loop (w->loop, EVLOOP_NONBLOCK); |
1797 | ev_loop (w->loop, EVLOOP_NONBLOCK); |
… | |
… | |
1753 | |
1837 | |
1754 | ev_stop (EV_A_ (W)w); |
1838 | ev_stop (EV_A_ (W)w); |
1755 | } |
1839 | } |
1756 | #endif |
1840 | #endif |
1757 | |
1841 | |
1758 | #if EV_STAT_ENABLE |
1842 | #if EV_FORK_ENABLE |
1759 | |
|
|
1760 | # ifdef _WIN32 |
|
|
1761 | # define lstat(a,b) stat(a,b) |
|
|
1762 | # endif |
|
|
1763 | |
|
|
1764 | void |
1843 | void |
1765 | ev_stat_stat (EV_P_ ev_stat *w) |
|
|
1766 | { |
|
|
1767 | if (lstat (w->path, &w->attr) < 0) |
|
|
1768 | w->attr.st_nlink = 0; |
|
|
1769 | else if (!w->attr.st_nlink) |
|
|
1770 | w->attr.st_nlink = 1; |
|
|
1771 | } |
|
|
1772 | |
|
|
1773 | static void |
|
|
1774 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
|
|
1775 | { |
|
|
1776 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
|
|
1777 | |
|
|
1778 | /* we copy this here each the time so that */ |
|
|
1779 | /* prev has the old value when the callback gets invoked */ |
|
|
1780 | w->prev = w->attr; |
|
|
1781 | ev_stat_stat (EV_A_ w); |
|
|
1782 | |
|
|
1783 | if (memcmp (&w->prev, &w->attr, sizeof (ev_statdata))) |
|
|
1784 | ev_feed_event (EV_A_ w, EV_STAT); |
|
|
1785 | } |
|
|
1786 | |
|
|
1787 | void |
|
|
1788 | ev_stat_start (EV_P_ ev_stat *w) |
1844 | ev_fork_start (EV_P_ ev_fork *w) |
1789 | { |
1845 | { |
1790 | if (expect_false (ev_is_active (w))) |
1846 | if (expect_false (ev_is_active (w))) |
1791 | return; |
1847 | return; |
1792 | |
1848 | |
1793 | /* since we use memcmp, we need to clear any padding data etc. */ |
|
|
1794 | memset (&w->prev, 0, sizeof (ev_statdata)); |
|
|
1795 | memset (&w->attr, 0, sizeof (ev_statdata)); |
|
|
1796 | |
|
|
1797 | ev_stat_stat (EV_A_ w); |
|
|
1798 | |
|
|
1799 | ev_timer_init (&w->timer, stat_timer_cb, w->interval, w->interval); |
|
|
1800 | ev_set_priority (&w->timer, ev_priority (w)); |
|
|
1801 | ev_timer_start (EV_A_ &w->timer); |
|
|
1802 | |
|
|
1803 | ev_start (EV_A_ (W)w, 1); |
1849 | ev_start (EV_A_ (W)w, ++forkcnt); |
|
|
1850 | array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); |
|
|
1851 | forks [forkcnt - 1] = w; |
1804 | } |
1852 | } |
1805 | |
1853 | |
1806 | void |
1854 | void |
1807 | ev_stat_stop (EV_P_ ev_stat *w) |
1855 | ev_fork_stop (EV_P_ ev_fork *w) |
1808 | { |
1856 | { |
1809 | ev_clear_pending (EV_A_ (W)w); |
1857 | ev_clear_pending (EV_A_ (W)w); |
1810 | if (expect_false (!ev_is_active (w))) |
1858 | if (expect_false (!ev_is_active (w))) |
1811 | return; |
1859 | return; |
1812 | |
1860 | |
1813 | ev_timer_stop (EV_A_ &w->timer); |
1861 | { |
|
|
1862 | int active = ((W)w)->active; |
|
|
1863 | forks [active - 1] = forks [--forkcnt]; |
|
|
1864 | ((W)forks [active - 1])->active = active; |
|
|
1865 | } |
1814 | |
1866 | |
1815 | ev_stop (EV_A_ (W)w); |
1867 | ev_stop (EV_A_ (W)w); |
1816 | } |
1868 | } |
1817 | #endif |
1869 | #endif |
1818 | |
1870 | |