Lines Matching full:ev

149 static int event_del_(struct event *ev, int blocking);
163 static inline void event_signal_closure(struct event_base *, struct event *ev);
164 static inline void event_persist_closure(struct event_base *, struct event *ev);
169 struct event *ev);
235 /* record that ev is now setup (that is, ready for an add) */ in HT_PROTOTYPE()
236 static void event_debug_note_setup_(const struct event *ev) in HT_PROTOTYPE()
243 find.ptr = ev; in HT_PROTOTYPE()
253 dent->ptr = ev; in HT_PROTOTYPE()
262 /* record that ev is no longer setup */
263 static void event_debug_note_teardown_(const struct event *ev) in event_debug_note_teardown_() argument
270 find.ptr = ev; in event_debug_note_teardown_()
280 /* Macro: record that ev is now added */
281 static void event_debug_note_add_(const struct event *ev) in event_debug_note_add_() argument
288 find.ptr = ev; in event_debug_note_add_()
298 __func__, ev, ev->ev_events, in event_debug_note_add_()
299 EV_SOCK_ARG(ev->ev_fd), ev->ev_flags); in event_debug_note_add_()
306 /* record that ev is no longer added */
307 static void event_debug_note_del_(const struct event *ev) in event_debug_note_del_() argument
314 find.ptr = ev; in event_debug_note_del_()
324 __func__, ev, ev->ev_events, in event_debug_note_del_()
325 EV_SOCK_ARG(ev->ev_fd), ev->ev_flags); in event_debug_note_del_()
332 /* assert that ev is setup (i.e., okay to add or inspect) */
333 static void event_debug_assert_is_setup_(const struct event *ev) in event_debug_assert_is_setup_() argument
340 find.ptr = ev; in event_debug_assert_is_setup_()
348 __func__, ev, ev->ev_events, in event_debug_assert_is_setup_()
349 EV_SOCK_ARG(ev->ev_fd), ev->ev_flags); in event_debug_assert_is_setup_()
353 /* assert that ev is not added (i.e., okay to tear down or set up again) */
354 static void event_debug_assert_not_added_(const struct event *ev) in event_debug_assert_not_added_() argument
361 find.ptr = ev; in event_debug_assert_not_added_()
369 __func__, ev, ev->ev_events, in event_debug_assert_not_added_()
370 EV_SOCK_ARG(ev->ev_fd), ev->ev_flags); in event_debug_assert_not_added_()
391 static void event_debug_note_setup_(const struct event *ev) { (void)ev; } in event_debug_note_setup_() argument
392 static void event_debug_note_teardown_(const struct event *ev) { (void)ev; } in event_debug_note_teardown_() argument
393 static void event_debug_note_add_(const struct event *ev) { (void)ev; } in event_debug_note_add_() argument
394 static void event_debug_note_del_(const struct event *ev) { (void)ev; } in event_debug_note_del_() argument
395 static void event_debug_assert_is_setup_(const struct event *ev) { (void)ev; } in event_debug_assert_is_setup_() argument
396 static void event_debug_assert_not_added_(const struct event *ev) { (void)ev; } in event_debug_assert_not_added_() argument
499 event_to_event_callback(struct event *ev) in event_to_event_callback() argument
501 return &ev->ev_evcallback; in event_to_event_callback()
782 struct event *ev = event_callback_to_event(evcb); in event_base_cancel_single_callback_() local
783 if (!(ev->ev_flags & EVLIST_INTERNAL)) { in event_base_cancel_single_callback_()
784 event_del_(ev, EVENT_DEL_EVEN_IF_FINALIZING); in event_base_cancel_single_callback_()
798 struct event *ev = event_callback_to_event(evcb); in event_base_cancel_single_callback_() local
799 ev->ev_evcallback.evcb_cb_union.evcb_evfinalize(ev, ev->ev_arg); in event_base_cancel_single_callback_()
801 mm_free(ev); in event_base_cancel_single_callback_()
841 struct event *ev; in event_base_free_() local
874 while ((ev = min_heap_top_(&base->timeheap)) != NULL) { in event_base_free_()
875 event_del(ev); in event_base_free_()
883 for (ev = TAILQ_FIRST(&ctl->events); ev; ) { in event_base_free_()
884 struct event *next = TAILQ_NEXT(ev, in event_base_free_()
886 if (!(ev->ev_flags & EVLIST_INTERNAL)) { in event_base_free_()
887 event_del(ev); in event_base_free_()
890 ev = next; in event_base_free_()
1354 event_signal_closure(struct event_base *base, struct event *ev) in event_signal_closure() argument
1360 ncalls = ev->ev_ncalls; in event_signal_closure()
1362 ev->ev_pncalls = &ncalls; in event_signal_closure()
1366 ev->ev_ncalls = ncalls; in event_signal_closure()
1368 ev->ev_pncalls = NULL; in event_signal_closure()
1369 (*ev->ev_callback)(ev->ev_fd, ev->ev_res, ev->ev_arg); in event_signal_closure()
1377 ev->ev_pncalls = NULL; in event_signal_closure()
1467 struct event *ev = NULL; in common_timeout_callback() local
1471 ev = TAILQ_FIRST(&ctl->events); in common_timeout_callback()
1472 if (!ev || ev->ev_timeout.tv_sec > now.tv_sec || in common_timeout_callback()
1473 (ev->ev_timeout.tv_sec == now.tv_sec && in common_timeout_callback()
1474 (ev->ev_timeout.tv_usec&MICROSECONDS_MASK) > now.tv_usec)) in common_timeout_callback()
1476 event_del_nolock_(ev, EVENT_DEL_NOBLOCK); in common_timeout_callback()
1477 event_active_nolock_(ev, EV_TIMEOUT, 1); in common_timeout_callback()
1479 if (ev) in common_timeout_callback()
1480 common_timeout_schedule(ctl, &now, ev); in common_timeout_callback()
1562 event_persist_closure(struct event_base *base, struct event *ev) in event_persist_closure() argument
1566 // Other fields of *ev that must be stored before executing in event_persist_closure()
1572 if (ev->ev_io_timeout.tv_sec || ev->ev_io_timeout.tv_usec) { in event_persist_closure()
1579 EVUTIL_ASSERT(is_same_common_timeout(&ev->ev_timeout, in event_persist_closure()
1580 &ev->ev_io_timeout)); in event_persist_closure()
1582 if (is_common_timeout(&ev->ev_timeout, base)) { in event_persist_closure()
1583 delay = ev->ev_io_timeout; in event_persist_closure()
1586 if (ev->ev_res & EV_TIMEOUT) { in event_persist_closure()
1587 relative_to = ev->ev_timeout; in event_persist_closure()
1593 delay = ev->ev_io_timeout; in event_persist_closure()
1594 if (ev->ev_res & EV_TIMEOUT) { in event_persist_closure()
1595 relative_to = ev->ev_timeout; in event_persist_closure()
1610 event_add_nolock_(ev, &run_at, 1); in event_persist_closure()
1614 evcb_callback = ev->ev_callback; in event_persist_closure()
1615 evcb_fd = ev->ev_fd; in event_persist_closure()
1616 evcb_res = ev->ev_res; in event_persist_closure()
1617 evcb_arg = ev->ev_arg; in event_persist_closure()
1644 struct event *ev=NULL; in event_process_active_single_queue() local
1646 ev = event_callback_to_event(evcb); in event_process_active_single_queue()
1648 if (ev->ev_events & EV_PERSIST || ev->ev_flags & EVLIST_FINALIZING) in event_process_active_single_queue()
1651 event_del_nolock_(ev, EVENT_DEL_NOBLOCK); in event_process_active_single_queue()
1654 ev, in event_process_active_single_queue()
1655 ev->ev_res & EV_READ ? "EV_READ " : " ", in event_process_active_single_queue()
1656 ev->ev_res & EV_WRITE ? "EV_WRITE " : " ", in event_process_active_single_queue()
1657 ev->ev_res & EV_CLOSED ? "EV_CLOSED " : " ", in event_process_active_single_queue()
1658 ev->ev_callback)); in event_process_active_single_queue()
1677 EVUTIL_ASSERT(ev != NULL); in event_process_active_single_queue()
1678 event_signal_closure(base, ev); in event_process_active_single_queue()
1681 EVUTIL_ASSERT(ev != NULL); in event_process_active_single_queue()
1682 event_persist_closure(base, ev); in event_process_active_single_queue()
1687 EVUTIL_ASSERT(ev != NULL); in event_process_active_single_queue()
1688 evcb_callback = *ev->ev_callback; in event_process_active_single_queue()
1689 res = ev->ev_res; in event_process_active_single_queue()
1691 evcb_callback(ev->ev_fd, res, ev->ev_arg); in event_process_active_single_queue()
1704 EVUTIL_ASSERT(ev != NULL); in event_process_active_single_queue()
1706 evcb_evfinalize = ev->ev_evcallback.evcb_cb_union.evcb_evfinalize; in event_process_active_single_queue()
1709 event_debug_note_teardown_(ev); in event_process_active_single_queue()
1710 evcb_evfinalize(ev, ev->ev_arg); in event_process_active_single_queue()
1712 mm_free(ev); in event_process_active_single_queue()
2033 EVBASE_ACQUIRE_LOCK(eonce->ev.ev_base, th_base_lock); in event_once_cb()
2035 EVBASE_RELEASE_LOCK(eonce->ev.ev_base, th_base_lock); in event_once_cb()
2036 event_debug_unassign(&eonce->ev); in event_once_cb()
2074 evtimer_assign(&eonce->ev, base, event_once_cb, eonce); in event_base_once()
2086 event_assign(&eonce->ev, base, fd, events, event_once_cb, eonce); in event_base_once()
2096 event_active_nolock_(&eonce->ev, EV_TIMEOUT, 1); in event_base_once()
2098 res = event_add_nolock_(&eonce->ev, tv, 0); in event_base_once()
2113 event_assign(struct event *ev, struct event_base *base, evutil_socket_t fd, short events, void (*ca… in event_assign() argument
2118 arg = ev; in event_assign()
2122 event_debug_assert_not_added_(ev); in event_assign()
2124 ev->ev_base = base; in event_assign()
2126 ev->ev_callback = callback; in event_assign()
2127 ev->ev_arg = arg; in event_assign()
2128 ev->ev_fd = fd; in event_assign()
2129 ev->ev_events = events; in event_assign()
2130 ev->ev_res = 0; in event_assign()
2131 ev->ev_flags = EVLIST_INIT; in event_assign()
2132 ev->ev_ncalls = 0; in event_assign()
2133 ev->ev_pncalls = NULL; in event_assign()
2141 ev->ev_closure = EV_CLOSURE_EVENT_SIGNAL; in event_assign()
2144 evutil_timerclear(&ev->ev_io_timeout); in event_assign()
2145 ev->ev_closure = EV_CLOSURE_EVENT_PERSIST; in event_assign()
2147 ev->ev_closure = EV_CLOSURE_EVENT; in event_assign()
2151 min_heap_elem_init_(ev); in event_assign()
2155 ev->ev_pri = base->nactivequeues / 2; in event_assign()
2158 event_debug_note_setup_(ev); in event_assign()
2164 event_base_set(struct event_base *base, struct event *ev) in event_base_set() argument
2167 if (ev->ev_flags != EVLIST_INIT) in event_base_set()
2170 event_debug_assert_is_setup_(ev); in event_base_set()
2172 ev->ev_base = base; in event_base_set()
2173 ev->ev_pri = base->nactivequeues/2; in event_base_set()
2179 event_set(struct event *ev, evutil_socket_t fd, short events, in event_set() argument
2183 r = event_assign(ev, current_base, fd, events, callback, arg); in event_set()
2196 struct event *ev = NULL; in event_base_get_running_event() local
2201 ev = event_callback_to_event(evcb); in event_base_get_running_event()
2204 return ev; in event_base_get_running_event()
2210 struct event *ev; in event_new() local
2211 ev = mm_malloc(sizeof(struct event)); in event_new()
2212 if (ev == NULL) in event_new()
2214 if (event_assign(ev, base, fd, events, cb, arg) < 0) { in event_new()
2215 mm_free(ev); in event_new()
2219 return (ev); in event_new()
2223 event_free(struct event *ev) in event_free() argument
2227 // event_debug_assert_is_setup_(ev); in event_free()
2230 event_del(ev); in event_free()
2231 event_debug_note_teardown_(ev); in event_free()
2232 mm_free(ev); in event_free()
2237 event_debug_unassign(struct event *ev) in event_debug_unassign() argument
2239 event_debug_assert_not_added_(ev); in event_debug_unassign()
2240 event_debug_note_teardown_(ev); in event_debug_unassign()
2242 ev->ev_flags &= ~EVLIST_INIT; in event_debug_unassign()
2247 event_finalize_nolock_(struct event_base *base, unsigned flags, struct event *ev, event_finalize_ca… in event_finalize_nolock_() argument
2252 event_del_nolock_(ev, EVENT_DEL_NOBLOCK); in event_finalize_nolock_()
2253 ev->ev_closure = closure; in event_finalize_nolock_()
2254 ev->ev_evcallback.evcb_cb_union.evcb_evfinalize = cb; in event_finalize_nolock_()
2255 event_active_nolock_(ev, EV_FINALIZE, 1); in event_finalize_nolock_()
2256 ev->ev_flags |= EVLIST_FINALIZING; in event_finalize_nolock_()
2261 event_finalize_impl_(unsigned flags, struct event *ev, event_finalize_callback_fn cb) in event_finalize_impl_() argument
2264 struct event_base *base = ev->ev_base; in event_finalize_impl_()
2271 r = event_finalize_nolock_(base, flags, ev, cb); in event_finalize_impl_()
2277 event_finalize(unsigned flags, struct event *ev, event_finalize_callback_fn cb) in event_finalize() argument
2279 return event_finalize_impl_(flags, ev, cb); in event_finalize()
2283 event_free_finalize(unsigned flags, struct event *ev, event_finalize_callback_fn cb) in event_free_finalize() argument
2285 return event_finalize_impl_(flags|EVENT_FINALIZE_FREE_, ev, cb); in event_free_finalize()
2291 struct event *ev = NULL; in event_callback_finalize_nolock_() local
2293 ev = event_callback_to_event(evcb); in event_callback_finalize_nolock_()
2294 event_del_nolock_(ev, EVENT_DEL_NOBLOCK); in event_callback_finalize_nolock_()
2356 event_priority_set(struct event *ev, int pri) in event_priority_set() argument
2358 event_debug_assert_is_setup_(ev); in event_priority_set()
2360 if (ev->ev_flags & EVLIST_ACTIVE) in event_priority_set()
2362 if (pri < 0 || pri >= ev->ev_base->nactivequeues) in event_priority_set()
2365 ev->ev_pri = pri; in event_priority_set()
2375 event_pending(const struct event *ev, short event, struct timeval *tv) in event_pending() argument
2379 if (EVUTIL_FAILURE_CHECK(ev->ev_base == NULL)) { in event_pending()
2384 EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); in event_pending()
2385 event_debug_assert_is_setup_(ev); in event_pending()
2387 if (ev->ev_flags & EVLIST_INSERTED) in event_pending()
2388 flags |= (ev->ev_events & (EV_READ|EV_WRITE|EV_CLOSED|EV_SIGNAL)); in event_pending()
2389 if (ev->ev_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER)) in event_pending()
2390 flags |= ev->ev_res; in event_pending()
2391 if (ev->ev_flags & EVLIST_TIMEOUT) in event_pending()
2398 struct timeval tmp = ev->ev_timeout; in event_pending()
2401 evutil_timeradd(&ev->ev_base->tv_clock_diff, &tmp, tv); in event_pending()
2404 EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); in event_pending()
2410 event_initialized(const struct event *ev) in event_initialized() argument
2412 if (!(ev->ev_flags & EVLIST_INIT)) in event_initialized()
2442 event_get_fd(const struct event *ev) in event_get_fd() argument
2444 event_debug_assert_is_setup_(ev); in event_get_fd()
2445 return ev->ev_fd; in event_get_fd()
2449 event_get_base(const struct event *ev) in event_get_base() argument
2451 event_debug_assert_is_setup_(ev); in event_get_base()
2452 return ev->ev_base; in event_get_base()
2456 event_get_events(const struct event *ev) in event_get_events() argument
2458 event_debug_assert_is_setup_(ev); in event_get_events()
2459 return ev->ev_events; in event_get_events()
2463 event_get_callback(const struct event *ev) in event_get_callback() argument
2465 event_debug_assert_is_setup_(ev); in event_get_callback()
2466 return ev->ev_callback; in event_get_callback()
2470 event_get_callback_arg(const struct event *ev) in event_get_callback_arg() argument
2472 event_debug_assert_is_setup_(ev); in event_get_callback_arg()
2473 return ev->ev_arg; in event_get_callback_arg()
2477 event_get_priority(const struct event *ev) in event_get_priority() argument
2479 event_debug_assert_is_setup_(ev); in event_get_priority()
2480 return ev->ev_pri; in event_get_priority()
2484 event_add(struct event *ev, const struct timeval *tv) in event_add() argument
2488 if (EVUTIL_FAILURE_CHECK(!ev->ev_base)) { in event_add()
2493 EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); in event_add()
2495 res = event_add_nolock_(ev, tv, 0); in event_add()
2497 EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); in event_add()
2555 event_remove_timer_nolock_(struct event *ev) in event_remove_timer_nolock_() argument
2557 struct event_base *base = ev->ev_base; in event_remove_timer_nolock_()
2560 event_debug_assert_is_setup_(ev); in event_remove_timer_nolock_()
2562 event_debug(("event_remove_timer_nolock: event: %p", ev)); in event_remove_timer_nolock_()
2565 if (ev->ev_flags & EVLIST_TIMEOUT) { in event_remove_timer_nolock_()
2566 event_queue_remove_timeout(base, ev); in event_remove_timer_nolock_()
2567 evutil_timerclear(&ev->ev_.ev_io.ev_timeout); in event_remove_timer_nolock_()
2574 event_remove_timer(struct event *ev) in event_remove_timer() argument
2578 if (EVUTIL_FAILURE_CHECK(!ev->ev_base)) { in event_remove_timer()
2583 EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); in event_remove_timer()
2585 res = event_remove_timer_nolock_(ev); in event_remove_timer()
2587 EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); in event_remove_timer()
2597 event_add_nolock_(struct event *ev, const struct timeval *tv, in event_add_nolock_() argument
2600 struct event_base *base = ev->ev_base; in event_add_nolock_()
2605 event_debug_assert_is_setup_(ev); in event_add_nolock_()
2609 ev, in event_add_nolock_()
2610 EV_SOCK_ARG(ev->ev_fd), in event_add_nolock_()
2611 ev->ev_events & EV_READ ? "EV_READ " : " ", in event_add_nolock_()
2612 ev->ev_events & EV_WRITE ? "EV_WRITE " : " ", in event_add_nolock_()
2613 ev->ev_events & EV_CLOSED ? "EV_CLOSED " : " ", in event_add_nolock_()
2615 ev->ev_callback)); in event_add_nolock_()
2617 EVUTIL_ASSERT(!(ev->ev_flags & ~EVLIST_ALL)); in event_add_nolock_()
2619 if (ev->ev_flags & EVLIST_FINALIZING) { in event_add_nolock_()
2628 if (tv != NULL && !(ev->ev_flags & EVLIST_TIMEOUT)) { in event_add_nolock_()
2639 if (base->current_event == event_to_event_callback(ev) && in event_add_nolock_()
2640 (ev->ev_events & EV_SIGNAL) in event_add_nolock_()
2647 if ((ev->ev_events & (EV_READ|EV_WRITE|EV_CLOSED|EV_SIGNAL)) && in event_add_nolock_()
2648 !(ev->ev_flags & (EVLIST_INSERTED|EVLIST_ACTIVE|EVLIST_ACTIVE_LATER))) { in event_add_nolock_()
2649 if (ev->ev_events & (EV_READ|EV_WRITE|EV_CLOSED)) in event_add_nolock_()
2650 res = evmap_io_add_(base, ev->ev_fd, ev); in event_add_nolock_()
2651 else if (ev->ev_events & EV_SIGNAL) in event_add_nolock_()
2652 res = evmap_signal_add_(base, (int)ev->ev_fd, ev); in event_add_nolock_()
2654 event_queue_insert_inserted(base, ev); in event_add_nolock_()
2680 if (ev->ev_closure == EV_CLOSURE_EVENT_PERSIST && !tv_is_absolute) in event_add_nolock_()
2681 ev->ev_io_timeout = *tv; in event_add_nolock_()
2684 if (ev->ev_flags & EVLIST_TIMEOUT) { in event_add_nolock_()
2685 event_queue_remove_timeout(base, ev); in event_add_nolock_()
2692 if ((ev->ev_flags & EVLIST_ACTIVE) && in event_add_nolock_()
2693 (ev->ev_res & EV_TIMEOUT)) { in event_add_nolock_()
2694 if (ev->ev_events & EV_SIGNAL) { in event_add_nolock_()
2698 if (ev->ev_ncalls && ev->ev_pncalls) { in event_add_nolock_()
2700 *ev->ev_pncalls = 0; in event_add_nolock_()
2704 event_queue_remove_active(base, event_to_event_callback(ev)); in event_add_nolock_()
2711 was_common = is_common_timeout(&ev->ev_timeout, base); in event_add_nolock_()
2712 old_timeout_idx = COMMON_TIMEOUT_IDX(&ev->ev_timeout); in event_add_nolock_()
2716 ev->ev_timeout = *tv; in event_add_nolock_()
2720 evutil_timeradd(&now, &tmp, &ev->ev_timeout); in event_add_nolock_()
2721 ev->ev_timeout.tv_usec |= in event_add_nolock_()
2724 evutil_timeradd(&now, tv, &ev->ev_timeout); in event_add_nolock_()
2729 ev, (int)tv->tv_sec, (int)tv->tv_usec, ev->ev_callback)); in event_add_nolock_()
2732 event_queue_reinsert_timeout(base, ev, was_common, common_timeout, old_timeout_idx); in event_add_nolock_()
2734 event_queue_insert_timeout(base, ev); in event_add_nolock_()
2739 get_common_timeout_list(base, &ev->ev_timeout); in event_add_nolock_()
2740 if (ev == TAILQ_FIRST(&ctl->events)) { in event_add_nolock_()
2741 common_timeout_schedule(ctl, &now, ev); in event_add_nolock_()
2751 if (min_heap_elt_is_top_(ev)) in event_add_nolock_()
2763 event_debug_note_add_(ev); in event_add_nolock_()
2769 event_del_(struct event *ev, int blocking) in event_del_() argument
2772 struct event_base *base = ev->ev_base; in event_del_()
2780 res = event_del_nolock_(ev, blocking); in event_del_()
2787 event_del(struct event *ev) in event_del() argument
2789 return event_del_(ev, EVENT_DEL_AUTOBLOCK); in event_del()
2793 event_del_block(struct event *ev) in event_del_block() argument
2795 return event_del_(ev, EVENT_DEL_BLOCK); in event_del_block()
2799 event_del_noblock(struct event *ev) in event_del_noblock() argument
2801 return event_del_(ev, EVENT_DEL_NOBLOCK); in event_del_noblock()
2810 event_del_nolock_(struct event *ev, int blocking) in event_del_nolock_() argument
2816 ev, EV_SOCK_ARG(ev->ev_fd), ev->ev_callback)); in event_del_nolock_()
2819 if (ev->ev_base == NULL) in event_del_nolock_()
2822 EVENT_BASE_ASSERT_LOCKED(ev->ev_base); in event_del_nolock_()
2825 if (ev->ev_flags & EVLIST_FINALIZING) { in event_del_nolock_()
2831 base = ev->ev_base; in event_del_nolock_()
2833 EVUTIL_ASSERT(!(ev->ev_flags & ~EVLIST_ALL)); in event_del_nolock_()
2836 if (ev->ev_events & EV_SIGNAL) { in event_del_nolock_()
2837 if (ev->ev_ncalls && ev->ev_pncalls) { in event_del_nolock_()
2839 *ev->ev_pncalls = 0; in event_del_nolock_()
2843 if (ev->ev_flags & EVLIST_TIMEOUT) { in event_del_nolock_()
2851 event_queue_remove_timeout(base, ev); in event_del_nolock_()
2854 if (ev->ev_flags & EVLIST_ACTIVE) in event_del_nolock_()
2855 event_queue_remove_active(base, event_to_event_callback(ev)); in event_del_nolock_()
2856 else if (ev->ev_flags & EVLIST_ACTIVE_LATER) in event_del_nolock_()
2857 event_queue_remove_active_later(base, event_to_event_callback(ev)); in event_del_nolock_()
2859 if (ev->ev_flags & EVLIST_INSERTED) { in event_del_nolock_()
2860 event_queue_remove_inserted(base, ev); in event_del_nolock_()
2861 if (ev->ev_events & (EV_READ|EV_WRITE|EV_CLOSED)) in event_del_nolock_()
2862 res = evmap_io_del_(base, ev->ev_fd, ev); in event_del_nolock_()
2864 res = evmap_signal_del_(base, (int)ev->ev_fd, ev); in event_del_nolock_()
2880 event_debug_note_del_(ev); in event_del_nolock_()
2889 base->current_event == event_to_event_callback(ev) && in event_del_nolock_()
2891 (blocking == EVENT_DEL_BLOCK || !(ev->ev_events & EV_FINALIZE))) { in event_del_nolock_()
2901 event_active(struct event *ev, int res, short ncalls) in event_active() argument
2903 if (EVUTIL_FAILURE_CHECK(!ev->ev_base)) { in event_active()
2908 EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); in event_active()
2910 event_debug_assert_is_setup_(ev); in event_active()
2912 event_active_nolock_(ev, res, ncalls); in event_active()
2914 EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); in event_active()
2919 event_active_nolock_(struct event *ev, int res, short ncalls) in event_active_nolock_() argument
2924 ev, EV_SOCK_ARG(ev->ev_fd), (int)res, ev->ev_callback)); in event_active_nolock_()
2926 base = ev->ev_base; in event_active_nolock_()
2929 if (ev->ev_flags & EVLIST_FINALIZING) { in event_active_nolock_()
2934 switch ((ev->ev_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER))) { in event_active_nolock_()
2941 ev->ev_res |= res; in event_active_nolock_()
2944 ev->ev_res |= res; in event_active_nolock_()
2947 ev->ev_res = res; in event_active_nolock_()
2951 if (ev->ev_pri < base->event_running_priority) in event_active_nolock_()
2954 if (ev->ev_events & EV_SIGNAL) { in event_active_nolock_()
2956 if (base->current_event == event_to_event_callback(ev) && in event_active_nolock_()
2962 ev->ev_ncalls = ncalls; in event_active_nolock_()
2963 ev->ev_pncalls = NULL; in event_active_nolock_()
2966 event_callback_activate_nolock_(base, event_to_event_callback(ev)); in event_active_nolock_()
2970 event_active_later_(struct event *ev, int res) in event_active_later_() argument
2972 EVBASE_ACQUIRE_LOCK(ev->ev_base, th_base_lock); in event_active_later_()
2973 event_active_later_nolock_(ev, res); in event_active_later_()
2974 EVBASE_RELEASE_LOCK(ev->ev_base, th_base_lock); in event_active_later_()
2978 event_active_later_nolock_(struct event *ev, int res) in event_active_later_nolock_() argument
2980 struct event_base *base = ev->ev_base; in event_active_later_nolock_()
2983 if (ev->ev_flags & (EVLIST_ACTIVE|EVLIST_ACTIVE_LATER)) { in event_active_later_nolock_()
2985 ev->ev_res |= res; in event_active_later_nolock_()
2989 ev->ev_res = res; in event_active_later_nolock_()
2991 event_callback_activate_later_nolock_(base, event_to_event_callback(ev)); in event_active_later_nolock_()
3147 struct event *ev; in timeout_next() local
3151 ev = min_heap_top_(&base->timeheap); in timeout_next()
3153 if (ev == NULL) { in timeout_next()
3164 if (evutil_timercmp(&ev->ev_timeout, &now, <=)) { in timeout_next()
3169 evutil_timersub(&ev->ev_timeout, &now, tv); in timeout_next()
3173 …event_debug(("timeout_next: event: %p, in %d seconds, %d useconds", ev, (int)tv->tv_sec, (int)tv->… in timeout_next()
3185 struct event *ev; in timeout_process() local
3193 while ((ev = min_heap_top_(&base->timeheap))) { in timeout_process()
3194 if (evutil_timercmp(&ev->ev_timeout, &now, >)) in timeout_process()
3198 event_del_nolock_(ev, EVENT_DEL_NOBLOCK); in timeout_process()
3201 ev, ev->ev_callback)); in timeout_process()
3202 event_active_nolock_(ev, EV_TIMEOUT, 1); in timeout_process()
3224 event_queue_remove_inserted(struct event_base *base, struct event *ev) in event_queue_remove_inserted() argument
3227 if (EVUTIL_FAILURE_CHECK(!(ev->ev_flags & EVLIST_INSERTED))) { in event_queue_remove_inserted()
3229 ev, EV_SOCK_ARG(ev->ev_fd), EVLIST_INSERTED); in event_queue_remove_inserted()
3232 DECR_EVENT_COUNT(base, ev->ev_flags); in event_queue_remove_inserted()
3233 ev->ev_flags &= ~EVLIST_INSERTED; in event_queue_remove_inserted()
3267 event_queue_remove_timeout(struct event_base *base, struct event *ev) in event_queue_remove_timeout() argument
3270 if (EVUTIL_FAILURE_CHECK(!(ev->ev_flags & EVLIST_TIMEOUT))) { in event_queue_remove_timeout()
3272 ev, EV_SOCK_ARG(ev->ev_fd), EVLIST_TIMEOUT); in event_queue_remove_timeout()
3275 DECR_EVENT_COUNT(base, ev->ev_flags); in event_queue_remove_timeout()
3276 ev->ev_flags &= ~EVLIST_TIMEOUT; in event_queue_remove_timeout()
3278 if (is_common_timeout(&ev->ev_timeout, base)) { in event_queue_remove_timeout()
3280 get_common_timeout_list(base, &ev->ev_timeout); in event_queue_remove_timeout()
3281 TAILQ_REMOVE(&ctl->events, ev, in event_queue_remove_timeout()
3284 min_heap_erase_(&base->timeheap, ev); in event_queue_remove_timeout()
3289 /* Remove and reinsert 'ev' into the timeout queue. */
3291 event_queue_reinsert_timeout(struct event_base *base, struct event *ev, in event_queue_reinsert_timeout() argument
3295 if (!(ev->ev_flags & EVLIST_TIMEOUT)) { in event_queue_reinsert_timeout()
3296 event_queue_insert_timeout(base, ev); in event_queue_reinsert_timeout()
3303 TAILQ_REMOVE(&ctl->events, ev, in event_queue_reinsert_timeout()
3305 ctl = get_common_timeout_list(base, &ev->ev_timeout); in event_queue_reinsert_timeout()
3306 insert_common_timeout_inorder(ctl, ev); in event_queue_reinsert_timeout()
3310 TAILQ_REMOVE(&ctl->events, ev, in event_queue_reinsert_timeout()
3312 min_heap_push_(&base->timeheap, ev); in event_queue_reinsert_timeout()
3315 min_heap_erase_(&base->timeheap, ev); in event_queue_reinsert_timeout()
3316 ctl = get_common_timeout_list(base, &ev->ev_timeout); in event_queue_reinsert_timeout()
3317 insert_common_timeout_inorder(ctl, ev); in event_queue_reinsert_timeout()
3320 min_heap_adjust_(&base->timeheap, ev); in event_queue_reinsert_timeout()
3329 /* Add 'ev' to the common timeout list in 'ev'. */
3332 struct event *ev) in insert_common_timeout_inorder() argument
3335 /* By all logic, we should just be able to append 'ev' to the end of in insert_common_timeout_inorder()
3336 * ctl->events, since the timeout on each 'ev' is set to {the common in insert_common_timeout_inorder()
3340 * the end of 'ev' to find the right insertion point. in insert_common_timeout_inorder()
3344 /* This timercmp is a little sneaky, since both ev and e have in insert_common_timeout_inorder()
3349 is_same_common_timeout(&e->ev_timeout, &ev->ev_timeout)); in insert_common_timeout_inorder()
3350 if (evutil_timercmp(&ev->ev_timeout, &e->ev_timeout, >=)) { in insert_common_timeout_inorder()
3351 TAILQ_INSERT_AFTER(&ctl->events, e, ev, in insert_common_timeout_inorder()
3356 TAILQ_INSERT_HEAD(&ctl->events, ev, in insert_common_timeout_inorder()
3361 event_queue_insert_inserted(struct event_base *base, struct event *ev) in event_queue_insert_inserted() argument
3365 if (EVUTIL_FAILURE_CHECK(ev->ev_flags & EVLIST_INSERTED)) { in event_queue_insert_inserted()
3367 ev, EV_SOCK_ARG(ev->ev_fd)); in event_queue_insert_inserted()
3371 INCR_EVENT_COUNT(base, ev->ev_flags); in event_queue_insert_inserted()
3373 ev->ev_flags |= EVLIST_INSERTED; in event_queue_insert_inserted()
3415 event_queue_insert_timeout(struct event_base *base, struct event *ev) in event_queue_insert_timeout() argument
3419 if (EVUTIL_FAILURE_CHECK(ev->ev_flags & EVLIST_TIMEOUT)) { in event_queue_insert_timeout()
3421 ev, EV_SOCK_ARG(ev->ev_fd)); in event_queue_insert_timeout()
3425 INCR_EVENT_COUNT(base, ev->ev_flags); in event_queue_insert_timeout()
3427 ev->ev_flags |= EVLIST_TIMEOUT; in event_queue_insert_timeout()
3429 if (is_common_timeout(&ev->ev_timeout, base)) { in event_queue_insert_timeout()
3431 get_common_timeout_list(base, &ev->ev_timeout); in event_queue_insert_timeout()
3432 insert_common_timeout_inorder(ctl, ev); in event_queue_insert_timeout()
3434 min_heap_push_(&base->timeheap, ev); in event_queue_insert_timeout()
3685 struct event *ev; in event_base_foreach_event_nolock_() local
3694 ev = base->timeheap.p[u]; in event_base_foreach_event_nolock_()
3695 if (ev->ev_flags & EVLIST_INSERTED) { in event_base_foreach_event_nolock_()
3699 if ((r = fn(base, ev, arg))) in event_base_foreach_event_nolock_()
3708 TAILQ_FOREACH(ev, &ctl->events, in event_base_foreach_event_nolock_()
3710 if (ev->ev_flags & EVLIST_INSERTED) { in event_base_foreach_event_nolock_()
3714 if ((r = fn(base, ev, arg))) in event_base_foreach_event_nolock_()
3730 ev = event_callback_to_event(evcb); in event_base_foreach_event_nolock_()
3731 if ((r = fn(base, ev, arg))) in event_base_foreach_event_nolock_()
3838 struct event *ev; in event_base_active_by_fd() local
3841 ev = base->timeheap.p[u]; in event_base_active_by_fd()
3842 if (ev->ev_fd == fd) { in event_base_active_by_fd()
3843 event_active_nolock_(ev, EV_TIMEOUT, 1); in event_base_active_by_fd()
3849 TAILQ_FOREACH(ev, &ctl->events, in event_base_active_by_fd()
3851 if (ev->ev_fd == fd) { in event_base_active_by_fd()
3852 event_active_nolock_(ev, EV_TIMEOUT, 1); in event_base_active_by_fd()
3975 struct event *ev, *p_ev; in event_base_assert_ok_nolock_() local
3976 ev = base->timeheap.p[i]; in event_base_assert_ok_nolock_()
3978 EVUTIL_ASSERT(ev->ev_flags & EVLIST_TIMEOUT); in event_base_assert_ok_nolock_()
3979 EVUTIL_ASSERT(evutil_timercmp(&p_ev->ev_timeout, &ev->ev_timeout, <=)); in event_base_assert_ok_nolock_()
3980 EVUTIL_ASSERT(ev->ev_timeout_pos.min_heap_idx == i); in event_base_assert_ok_nolock_()
3986 struct event *last=NULL, *ev; in event_base_assert_ok_nolock_() local
3990 TAILQ_FOREACH(ev, &ctl->events, ev_timeout_pos.ev_next_with_common_timeout) { in event_base_assert_ok_nolock_()
3992 EVUTIL_ASSERT(evutil_timercmp(&last->ev_timeout, &ev->ev_timeout, <=)); in event_base_assert_ok_nolock_()
3993 EVUTIL_ASSERT(ev->ev_flags & EVLIST_TIMEOUT); in event_base_assert_ok_nolock_()
3994 EVUTIL_ASSERT(is_common_timeout(&ev->ev_timeout,base)); in event_base_assert_ok_nolock_()
3995 EVUTIL_ASSERT(COMMON_TIMEOUT_IDX(&ev->ev_timeout) == i); in event_base_assert_ok_nolock_()
3996 last = ev; in event_base_assert_ok_nolock_()