Lines Matching full:base
142 static void event_queue_make_later_events_active(struct event_base *base);
144 static int evthread_make_base_notifiable_nolock_(struct event_base *base);
162 static int evthread_notify_base(struct event_base *base);
360 #define EVENT_BASE_ASSERT_LOCKED(base) \ argument
361 EVLOCK_ASSERT_LOCKED((base)->th_base_lock)
367 /** Set 'tp' to the current time according to 'base'. We must hold the lock
368 * on 'base'. If there is a cached time, return it. Otherwise, use
373 gettime(struct event_base *base, struct timeval *tp)
375 EVENT_BASE_ASSERT_LOCKED(base);
377 if (base->tv_cache.tv_sec) {
378 *tp = base->tv_cache;
382 if (evutil_gettime_monotonic_(&base->monotonic_timer, tp) == -1) {
386 if (base->last_updated_clock_diff + CLOCK_SYNC_INTERVAL
390 evutil_timersub(&tv, tp, &base->tv_clock_diff);
391 base->last_updated_clock_diff = tp->tv_sec;
398 event_base_gettimeofday_cached(struct event_base *base, struct timeval *tv) in event_base_gettimeofday_cached() argument
401 if (!base) { in event_base_gettimeofday_cached()
402 base = current_base; in event_base_gettimeofday_cached()
407 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_gettimeofday_cached()
408 if (base->tv_cache.tv_sec == 0) { in event_base_gettimeofday_cached()
411 evutil_timeradd(&base->tv_cache, &base->tv_clock_diff, tv); in event_base_gettimeofday_cached()
414 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_gettimeofday_cached()
418 /** Make 'base' have no current cached time. */
420 clear_time_cache(struct event_base *base) in clear_time_cache() argument
422 base->tv_cache.tv_sec = 0; in clear_time_cache()
425 /** Replace the cached time in 'base' with the current time. */
427 update_time_cache(struct event_base *base) in update_time_cache() argument
429 base->tv_cache.tv_sec = 0; in update_time_cache()
430 if (!(base->flags & EVENT_BASE_FLAG_NO_CACHE_TIME)) in update_time_cache()
431 gettime(base, &base->tv_cache); in update_time_cache()
435 event_base_update_cache_time(struct event_base *base) in event_base_update_cache_time() argument
438 if (!base) { in event_base_update_cache_time()
439 base = current_base; in event_base_update_cache_time()
444 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_update_cache_time()
445 if (base->running_loop) in event_base_update_cache_time()
446 update_time_cache(base); in event_base_update_cache_time()
447 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_update_cache_time()
467 struct event_base *base = event_base_new_with_config(NULL); in event_init() local
469 if (base == NULL) { in event_init()
474 current_base = base; in event_init()
476 return (base); in event_init()
482 struct event_base *base = NULL; in event_base_new() local
485 base = event_base_new_with_config(cfg); in event_base_new()
488 return base; in event_base_new()
524 event_base_get_features(const struct event_base *base) in event_base_get_features() argument
526 return base->evsel->features; in event_base_get_features()
568 struct event_base *base; in event_base_new_with_config() local
575 if ((base = mm_calloc(1, sizeof(struct event_base))) == NULL) { in event_base_new_with_config()
581 base->flags = cfg->flags; in event_base_new_with_config()
593 base->flags |= EVENT_BASE_FLAG_PRECISE_TIMER; in event_base_new_with_config()
596 evutil_configure_monotonic_time_(&base->monotonic_timer, flags); in event_base_new_with_config()
598 gettime(base, &tmp); in event_base_new_with_config()
601 min_heap_ctor_(&base->timeheap); in event_base_new_with_config()
603 base->sig.ev_signal_pair[0] = -1; in event_base_new_with_config()
604 base->sig.ev_signal_pair[1] = -1; in event_base_new_with_config()
605 base->th_notify_fd[0] = -1; in event_base_new_with_config()
606 base->th_notify_fd[1] = -1; in event_base_new_with_config()
608 TAILQ_INIT(&base->active_later_queue); in event_base_new_with_config()
610 evmap_io_initmap_(&base->io); in event_base_new_with_config()
611 evmap_signal_initmap_(&base->sigmap); in event_base_new_with_config()
612 event_changelist_init_(&base->changelist); in event_base_new_with_config()
614 base->evbase = NULL; in event_base_new_with_config()
617 memcpy(&base->max_dispatch_time, in event_base_new_with_config()
619 base->limit_callbacks_after_prio = in event_base_new_with_config()
622 base->max_dispatch_time.tv_sec = -1; in event_base_new_with_config()
623 base->limit_callbacks_after_prio = 1; in event_base_new_with_config()
626 base->max_dispatch_callbacks = cfg->max_dispatch_callbacks; in event_base_new_with_config()
628 base->max_dispatch_callbacks = INT_MAX; in event_base_new_with_config()
630 if (base->max_dispatch_callbacks == INT_MAX && in event_base_new_with_config()
631 base->max_dispatch_time.tv_sec == -1) in event_base_new_with_config()
632 base->limit_callbacks_after_prio = INT_MAX; in event_base_new_with_config()
634 for (i = 0; eventops[i] && !base->evbase; i++) { in event_base_new_with_config()
650 base->evsel = eventops[i]; in event_base_new_with_config()
652 base->evbase = base->evsel->init(base); in event_base_new_with_config()
655 if (base->evbase == NULL) { in event_base_new_with_config()
658 base->evsel = NULL; in event_base_new_with_config()
659 event_base_free(base); in event_base_new_with_config()
664 event_msgx("libevent using: %s", base->evsel->name); in event_base_new_with_config()
667 if (event_base_priority_init(base, 1) < 0) { in event_base_new_with_config()
668 event_base_free(base); in event_base_new_with_config()
682 EVTHREAD_ALLOC_LOCK(base->th_base_lock, 0); in event_base_new_with_config()
683 EVTHREAD_ALLOC_COND(base->current_event_cond); in event_base_new_with_config()
684 r = evthread_make_base_notifiable(base); in event_base_new_with_config()
686 event_warnx("%s: Unable to make base notifiable.", __func__); in event_base_new_with_config()
687 event_base_free(base); in event_base_new_with_config()
695 event_base_start_iocp_(base, cfg->n_cpus_hint); in event_base_new_with_config()
698 return (base); in event_base_new_with_config()
702 event_base_start_iocp_(struct event_base *base, int n_cpus) in event_base_start_iocp_() argument
705 if (base->iocp) in event_base_start_iocp_()
707 base->iocp = event_iocp_port_launch_(n_cpus); in event_base_start_iocp_()
708 if (!base->iocp) { in event_base_start_iocp_()
719 event_base_stop_iocp_(struct event_base *base) in event_base_stop_iocp_() argument
724 if (!base->iocp) in event_base_stop_iocp_()
726 rv = event_iocp_shutdown_(base->iocp, -1); in event_base_stop_iocp_()
728 base->iocp = NULL; in event_base_stop_iocp_()
733 event_base_cancel_single_callback_(struct event_base *base, in event_base_cancel_single_callback_() argument
746 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_cancel_single_callback_()
747 event_callback_cancel_nolock_(base, evcb, 1); in event_base_cancel_single_callback_()
748 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_cancel_single_callback_()
772 static int event_base_free_queues_(struct event_base *base, int run_finalizers) in event_base_free_queues_() argument
776 for (i = 0; i < base->nactivequeues; ++i) { in event_base_free_queues_()
778 for (evcb = TAILQ_FIRST(&base->activequeues[i]); evcb; ) { in event_base_free_queues_()
780 deleted += event_base_cancel_single_callback_(base, evcb, run_finalizers); in event_base_free_queues_()
787 while ((evcb = TAILQ_FIRST(&base->active_later_queue))) { in event_base_free_queues_()
788 deleted += event_base_cancel_single_callback_(base, evcb, run_finalizers); in event_base_free_queues_()
796 event_base_free_(struct event_base *base, int run_finalizers) in event_base_free_() argument
801 * the base, then the contending thread will be very sad soon. */ in event_base_free_()
805 if (base == NULL && current_base) in event_base_free_()
806 base = current_base; in event_base_free_()
808 if (base == NULL) { in event_base_free_()
809 event_warnx("%s: no base to free", __func__); in event_base_free_()
815 event_base_stop_iocp_(base); in event_base_free_()
819 if (base->th_notify_fd[0] != -1) { in event_base_free_()
820 event_del(&base->th_notify); in event_base_free_()
821 EVUTIL_CLOSESOCKET(base->th_notify_fd[0]); in event_base_free_()
822 if (base->th_notify_fd[1] != -1) in event_base_free_()
823 EVUTIL_CLOSESOCKET(base->th_notify_fd[1]); in event_base_free_()
824 base->th_notify_fd[0] = -1; in event_base_free_()
825 base->th_notify_fd[1] = -1; in event_base_free_()
826 event_debug_unassign(&base->th_notify); in event_base_free_()
830 evmap_delete_all_(base); in event_base_free_()
832 while ((ev = min_heap_top_(&base->timeheap)) != NULL) { in event_base_free_()
836 for (i = 0; i < base->n_common_timeouts; ++i) { in event_base_free_()
838 base->common_timeout_queues[i]; in event_base_free_()
852 if (base->common_timeout_queues) in event_base_free_()
853 mm_free(base->common_timeout_queues); in event_base_free_()
864 int i = event_base_free_queues_(base, run_finalizers); in event_base_free_()
872 event_debug(("%s: %d events were still set in base", in event_base_free_()
875 while (LIST_FIRST(&base->once_events)) { in event_base_free_()
876 struct event_once *eonce = LIST_FIRST(&base->once_events); in event_base_free_()
881 if (base->evsel != NULL && base->evsel->dealloc != NULL) in event_base_free_()
882 base->evsel->dealloc(base); in event_base_free_()
884 for (i = 0; i < base->nactivequeues; ++i) in event_base_free_()
885 EVUTIL_ASSERT(TAILQ_EMPTY(&base->activequeues[i])); in event_base_free_()
887 EVUTIL_ASSERT(min_heap_empty_(&base->timeheap)); in event_base_free_()
888 min_heap_dtor_(&base->timeheap); in event_base_free_()
890 mm_free(base->activequeues); in event_base_free_()
892 evmap_io_clear_(&base->io); in event_base_free_()
893 evmap_signal_clear_(&base->sigmap); in event_base_free_()
894 event_changelist_freemem_(&base->changelist); in event_base_free_()
896 EVTHREAD_FREE_LOCK(base->th_base_lock, 0); in event_base_free_()
897 EVTHREAD_FREE_COND(base->current_event_cond); in event_base_free_()
900 if (base == current_base) in event_base_free_()
902 mm_free(base); in event_base_free_()
906 event_base_free_nofinalize(struct event_base *base) in event_base_free_nofinalize() argument
908 event_base_free_(base, 0); in event_base_free_nofinalize()
912 event_base_free(struct event_base *base) in event_base_free() argument
914 event_base_free_(base, 1); in event_base_free()
936 /* reinitialize the event base after a fork */
938 event_reinit(struct event_base *base) in event_reinit() argument
945 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_reinit()
947 evsel = base->evsel; in event_reinit()
959 base->evsel = &nil_eventop; in event_reinit()
968 if (base->sig.ev_signal_added) { in event_reinit()
969 event_del_nolock_(&base->sig.ev_signal, EVENT_DEL_AUTOBLOCK); in event_reinit()
970 event_debug_unassign(&base->sig.ev_signal); in event_reinit()
971 memset(&base->sig.ev_signal, 0, sizeof(base->sig.ev_signal)); in event_reinit()
973 base->sig.ev_signal_added = 0; in event_reinit()
975 if (base->sig.ev_signal_pair[0] != -1) in event_reinit()
976 EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[0]); in event_reinit()
977 if (base->sig.ev_signal_pair[1] != -1) in event_reinit()
978 EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[1]); in event_reinit()
979 if (base->th_notify_fn != NULL) { in event_reinit()
981 base->th_notify_fn = NULL; in event_reinit()
983 if (base->th_notify_fd[0] != -1) { in event_reinit()
984 event_del_nolock_(&base->th_notify, EVENT_DEL_AUTOBLOCK); in event_reinit()
985 EVUTIL_CLOSESOCKET(base->th_notify_fd[0]); in event_reinit()
986 if (base->th_notify_fd[1] != -1) in event_reinit()
987 EVUTIL_CLOSESOCKET(base->th_notify_fd[1]); in event_reinit()
988 base->th_notify_fd[0] = -1; in event_reinit()
989 base->th_notify_fd[1] = -1; in event_reinit()
990 event_debug_unassign(&base->th_notify); in event_reinit()
994 base->evsel = evsel; in event_reinit()
1006 if (base->evsel->dealloc != NULL) in event_reinit()
1007 base->evsel->dealloc(base); in event_reinit()
1008 base->evbase = evsel->init(base); in event_reinit()
1009 if (base->evbase == NULL) { in event_reinit()
1019 event_changelist_freemem_(&base->changelist); in event_reinit()
1024 if (evmap_reinit_(base) < 0) in event_reinit()
1027 res = evsig_init_(base); in event_reinit()
1029 res = event_add_nolock_(&base->sig.ev_signal, NULL, 0); in event_reinit()
1031 base->sig.ev_signal_added = 1; in event_reinit()
1038 res = evthread_make_base_notifiable_nolock_(base); in event_reinit()
1041 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_reinit()
1047 event_gettime_monotonic(struct event_base *base, struct timeval *tv) in event_gettime_monotonic() argument
1051 if (base && tv) { in event_gettime_monotonic()
1052 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_gettime_monotonic()
1053 rv = evutil_gettime_monotonic_(&(base->monotonic_timer), tv); in event_gettime_monotonic()
1054 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_gettime_monotonic()
1197 event_base_priority_init(struct event_base *base, int npriorities) in event_base_priority_init() argument
1202 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_priority_init()
1204 if (N_ACTIVE_CALLBACKS(base) || npriorities < 1 in event_base_priority_init()
1208 if (npriorities == base->nactivequeues) in event_base_priority_init()
1211 if (base->nactivequeues) { in event_base_priority_init()
1212 mm_free(base->activequeues); in event_base_priority_init()
1213 base->nactivequeues = 0; in event_base_priority_init()
1217 base->activequeues = (struct evcallback_list *) in event_base_priority_init()
1219 if (base->activequeues == NULL) { in event_base_priority_init()
1223 base->nactivequeues = npriorities; in event_base_priority_init()
1225 for (i = 0; i < base->nactivequeues; ++i) { in event_base_priority_init()
1226 TAILQ_INIT(&base->activequeues[i]); in event_base_priority_init()
1232 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_priority_init()
1237 event_base_get_npriorities(struct event_base *base) in event_base_get_npriorities() argument
1241 if (base == NULL) in event_base_get_npriorities()
1242 base = current_base; in event_base_get_npriorities()
1244 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_get_npriorities()
1245 n = base->nactivequeues; in event_base_get_npriorities()
1246 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_get_npriorities()
1251 event_base_get_num_events(struct event_base *base, unsigned int type) in event_base_get_num_events() argument
1255 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_get_num_events()
1258 r += base->event_count_active; in event_base_get_num_events()
1261 r += base->virtual_event_count; in event_base_get_num_events()
1264 r += base->event_count; in event_base_get_num_events()
1266 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_get_num_events()
1272 event_base_get_max_events(struct event_base *base, unsigned int type, int clear) in event_base_get_max_events() argument
1276 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_get_max_events()
1279 r += base->event_count_active_max; in event_base_get_max_events()
1281 base->event_count_active_max = 0; in event_base_get_max_events()
1285 r += base->virtual_event_count_max; in event_base_get_max_events()
1287 base->virtual_event_count_max = 0; in event_base_get_max_events()
1291 r += base->event_count_max; in event_base_get_max_events()
1293 base->event_count_max = 0; in event_base_get_max_events()
1296 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_get_max_events()
1303 event_haveevents(struct event_base *base) in event_haveevents() argument
1306 return (base->virtual_event_count > 0 || base->event_count > 0); in event_haveevents()
1311 event_signal_closure(struct event_base *base, struct event *ev) in event_signal_closure() argument
1320 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_signal_closure()
1328 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_signal_closure()
1329 should_break = base->event_break; in event_signal_closure()
1330 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_signal_closure()
1363 /** Return true iff if 'tv' is a common timeout in 'base' */
1366 const struct event_base *base) in is_common_timeout() argument
1372 return idx < base->n_common_timeouts; in is_common_timeout()
1387 get_common_timeout_list(struct event_base *base, const struct timeval *tv) in get_common_timeout_list() argument
1389 return base->common_timeout_queues[COMMON_TIMEOUT_IDX(tv)]; in get_common_timeout_list()
1395 struct event_base *base)
1398 &get_common_timeout_list(base, tv)->duration;
1423 struct event_base *base = ctl->base; in common_timeout_callback() local
1425 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in common_timeout_callback()
1426 gettime(base, &now); in common_timeout_callback()
1438 EVBASE_RELEASE_LOCK(base, th_base_lock); in common_timeout_callback()
1444 event_base_init_common_timeout(struct event_base *base, in event_base_init_common_timeout() argument
1452 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_init_common_timeout()
1455 if (is_common_timeout(duration, base)) in event_base_init_common_timeout()
1461 for (i = 0; i < base->n_common_timeouts; ++i) { in event_base_init_common_timeout()
1463 base->common_timeout_queues[i]; in event_base_init_common_timeout()
1467 EVUTIL_ASSERT(is_common_timeout(&ctl->duration, base)); in event_base_init_common_timeout()
1472 if (base->n_common_timeouts == MAX_COMMON_TIMEOUTS) { in event_base_init_common_timeout()
1478 if (base->n_common_timeouts_allocated == base->n_common_timeouts) { in event_base_init_common_timeout()
1479 int n = base->n_common_timeouts < 16 ? 16 : in event_base_init_common_timeout()
1480 base->n_common_timeouts*2; in event_base_init_common_timeout()
1482 mm_realloc(base->common_timeout_queues, in event_base_init_common_timeout()
1488 base->n_common_timeouts_allocated = n; in event_base_init_common_timeout()
1489 base->common_timeout_queues = newqueues; in event_base_init_common_timeout()
1500 (base->n_common_timeouts << COMMON_TIMEOUT_IDX_SHIFT); in event_base_init_common_timeout()
1501 evtimer_assign(&new_ctl->timeout_event, base, in event_base_init_common_timeout()
1505 new_ctl->base = base; in event_base_init_common_timeout()
1506 base->common_timeout_queues[base->n_common_timeouts++] = new_ctl; in event_base_init_common_timeout()
1511 EVUTIL_ASSERT(is_common_timeout(result, base)); in event_base_init_common_timeout()
1513 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_init_common_timeout()
1519 event_persist_closure(struct event_base *base, struct event *ev) in event_persist_closure() argument
1538 gettime(base, &now); in event_persist_closure()
1539 if (is_common_timeout(&ev->ev_timeout, base)) { in event_persist_closure()
1577 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_persist_closure()
1591 event_process_active_single_queue(struct event_base *base, in event_process_active_single_queue() argument
1606 event_queue_remove_active(base, evcb); in event_process_active_single_queue()
1617 event_queue_remove_active(base, evcb); in event_process_active_single_queue()
1627 base->current_event = evcb; in event_process_active_single_queue()
1629 base->current_event_waiters = 0; in event_process_active_single_queue()
1635 event_signal_closure(base, ev); in event_process_active_single_queue()
1639 event_persist_closure(base, ev); in event_process_active_single_queue()
1645 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_process_active_single_queue()
1651 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_process_active_single_queue()
1660 base->current_event = NULL; in event_process_active_single_queue()
1663 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_process_active_single_queue()
1672 base->current_event = NULL; in event_process_active_single_queue()
1674 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_process_active_single_queue()
1682 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_process_active_single_queue()
1683 base->current_event = NULL; in event_process_active_single_queue()
1685 if (base->current_event_waiters) { in event_process_active_single_queue()
1686 base->current_event_waiters = 0; in event_process_active_single_queue()
1687 EVTHREAD_COND_BROADCAST(base->current_event_cond); in event_process_active_single_queue()
1691 if (base->event_break) in event_process_active_single_queue()
1697 update_time_cache(base); in event_process_active_single_queue()
1698 gettime(base, &now); in event_process_active_single_queue()
1702 if (base->event_continue) in event_process_active_single_queue()
1715 event_process_active(struct event_base *base) in event_process_active() argument
1722 const int maxcb = base->max_dispatch_callbacks; in event_process_active()
1723 const int limit_after_prio = base->limit_callbacks_after_prio; in event_process_active()
1724 if (base->max_dispatch_time.tv_sec >= 0) { in event_process_active()
1725 update_time_cache(base); in event_process_active()
1726 gettime(base, &tv); in event_process_active()
1727 evutil_timeradd(&base->max_dispatch_time, &tv, &tv); in event_process_active()
1733 for (i = 0; i < base->nactivequeues; ++i) { in event_process_active()
1734 if (TAILQ_FIRST(&base->activequeues[i]) != NULL) { in event_process_active()
1735 base->event_running_priority = i; in event_process_active()
1736 activeq = &base->activequeues[i]; in event_process_active()
1738 c = event_process_active_single_queue(base, activeq, in event_process_active()
1741 c = event_process_active_single_queue(base, activeq, in event_process_active()
1754 base->event_running_priority = -1; in event_process_active()
1776 event_base_get_method(const struct event_base *base) in event_base_get_method() argument
1778 EVUTIL_ASSERT(base); in event_base_get_method()
1779 return (base->evsel->name); in event_base_get_method()
1787 struct event_base *base = arg; in event_loopexit_cb() local
1788 base->event_gotterm = 1; in event_loopexit_cb()
1878 event_base_loop(struct event_base *base, int flags) in event_base_loop() argument
1880 const struct eventop *evsel = base->evsel; in event_base_loop()
1887 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_loop()
1889 if (base->running_loop) { in event_base_loop()
1892 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_loop()
1896 base->running_loop = 1; in event_base_loop()
1898 clear_time_cache(base); in event_base_loop()
1900 if (base->sig.ev_signal_added && base->sig.ev_n_signals_added) in event_base_loop()
1901 evsig_set_base_(base); in event_base_loop()
1906 base->th_owner_id = EVTHREAD_GET_ID(); in event_base_loop()
1909 base->event_gotterm = base->event_break = 0; in event_base_loop()
1912 base->event_continue = 0; in event_base_loop()
1913 base->n_deferreds_queued = 0; in event_base_loop()
1916 if (base->event_gotterm) { in event_base_loop()
1920 if (base->event_break) { in event_base_loop()
1925 if (!N_ACTIVE_CALLBACKS(base) && !(flags & EVLOOP_NONBLOCK)) { in event_base_loop()
1926 timeout_next(base, &tv_p); in event_base_loop()
1937 !event_haveevents(base) && !N_ACTIVE_CALLBACKS(base)) { in event_base_loop()
1943 event_queue_make_later_events_active(base); in event_base_loop()
1945 clear_time_cache(base); in event_base_loop()
1947 res = evsel->dispatch(base, tv_p); in event_base_loop()
1956 update_time_cache(base); in event_base_loop()
1958 timeout_process(base); in event_base_loop()
1960 if (N_ACTIVE_CALLBACKS(base)) { in event_base_loop()
1961 int n = event_process_active(base); in event_base_loop()
1963 && N_ACTIVE_CALLBACKS(base) == 0 in event_base_loop()
1972 clear_time_cache(base); in event_base_loop()
1973 base->running_loop = 0; in event_base_loop()
1975 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_loop()
2006 event_base_once(struct event_base *base, evutil_socket_t fd, short events, in event_base_once() argument
2026 evtimer_assign(&eonce->ev, base, event_once_cb, eonce); in event_base_once()
2038 event_assign(&eonce->ev, base, fd, events, event_once_cb, eonce); in event_base_once()
2046 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_once()
2056 LIST_INSERT_HEAD(&base->once_events, eonce, next_once); in event_base_once()
2058 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_once()
2065 event_assign(struct event *ev, struct event_base *base, evutil_socket_t fd, short events, void (*ca… in event_assign() argument
2067 if (!base) in event_assign()
2068 base = current_base; in event_assign()
2074 ev->ev_base = base; in event_assign()
2103 if (base != NULL) { in event_assign()
2105 ev->ev_pri = base->nactivequeues / 2; in event_assign()
2114 event_base_set(struct event_base *base, struct event *ev) in event_base_set() argument
2116 /* Only innocent events may be assigned to a different base */ in event_base_set()
2122 ev->ev_base = base; in event_base_set()
2123 ev->ev_pri = base->nactivequeues/2; in event_base_set()
2144 event_base_get_running_event(struct event_base *base) in event_base_get_running_event() argument
2147 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_get_running_event()
2148 if (EVBASE_IN_THREAD(base)) { in event_base_get_running_event()
2149 struct event_callback *evcb = base->current_event; in event_base_get_running_event()
2153 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_get_running_event()
2158 event_new(struct event_base *base, evutil_socket_t fd, short events, void (*cb)(evutil_socket_t, sh… in event_new() argument
2164 if (event_assign(ev, base, fd, events, cb, arg) < 0) { in event_new()
2197 event_finalize_nolock_(struct event_base *base, unsigned flags, struct event *ev, event_finalize_ca… in event_finalize_nolock_() argument
2214 struct event_base *base = ev->ev_base; in event_finalize_impl_() local
2215 if (EVUTIL_FAILURE_CHECK(!base)) { in event_finalize_impl_()
2220 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_finalize_impl_()
2221 r = event_finalize_nolock_(base, flags, ev, cb); in event_finalize_impl_()
2222 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_finalize_impl_()
2239 event_callback_finalize_nolock_(struct event_base *base, unsigned flags, struct event_callback *evc… in event_callback_finalize_nolock_() argument
2246 event_callback_cancel_nolock_(base, evcb, 0); /*XXX can this fail?*/ in event_callback_finalize_nolock_()
2251 event_callback_activate_nolock_(base, evcb); /* XXX can this really fail?*/ in event_callback_finalize_nolock_()
2256 event_callback_finalize_(struct event_base *base, unsigned flags, struct event_callback *evcb, void… in event_callback_finalize_() argument
2258 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_callback_finalize_()
2259 event_callback_finalize_nolock_(base, flags, evcb, cb); in event_callback_finalize_()
2260 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_callback_finalize_()
2267 event_callback_finalize_many_(struct event_base *base, int n_cbs, struct event_callback **evcbs, vo… in event_callback_finalize_many_() argument
2271 if (base == NULL) in event_callback_finalize_many_()
2272 base = current_base; in event_callback_finalize_many_()
2274 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_callback_finalize_many_()
2283 if (evcb == base->current_event) { in event_callback_finalize_many_()
2284 event_callback_finalize_nolock_(base, 0, evcb, cb); in event_callback_finalize_many_()
2287 event_callback_cancel_nolock_(base, evcb, 0); in event_callback_finalize_many_()
2293 event_callback_finalize_nolock_(base, 0, evcbs[0], cb); in event_callback_finalize_many_()
2296 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_callback_finalize_many_()
2457 evthread_notify_base_default(struct event_base *base) in evthread_notify_base_default() argument
2463 r = send(base->th_notify_fd[1], buf, 1, 0); in evthread_notify_base_default()
2465 r = write(base->th_notify_fd[1], buf, 1); in evthread_notify_base_default()
2474 evthread_notify_base_eventfd(struct event_base *base) in evthread_notify_base_eventfd() argument
2479 r = write(base->th_notify_fd[0], (void*) &msg, sizeof(msg)); in evthread_notify_base_eventfd()
2487 /** Tell the thread currently running the event_loop for base (if any) that it
2491 evthread_notify_base(struct event_base *base) in evthread_notify_base() argument
2493 EVENT_BASE_ASSERT_LOCKED(base); in evthread_notify_base()
2494 if (!base->th_notify_fn) in evthread_notify_base()
2496 if (base->is_notify_pending) in evthread_notify_base()
2498 base->is_notify_pending = 1; in evthread_notify_base()
2499 return base->th_notify_fn(base); in evthread_notify_base()
2507 struct event_base *base = ev->ev_base; in event_remove_timer_nolock_() local
2509 EVENT_BASE_ASSERT_LOCKED(base); in event_remove_timer_nolock_()
2516 event_queue_remove_timeout(base, ev); in event_remove_timer_nolock_()
2550 struct event_base *base = ev->ev_base; in event_add_nolock_() local
2554 EVENT_BASE_ASSERT_LOCKED(base); in event_add_nolock_()
2579 if (min_heap_reserve_(&base->timeheap, in event_add_nolock_()
2580 1 + min_heap_size_(&base->timeheap)) == -1) in event_add_nolock_()
2589 if (base->current_event == event_to_event_callback(ev) && in event_add_nolock_()
2591 && !EVBASE_IN_THREAD(base)) { in event_add_nolock_()
2592 ++base->current_event_waiters; in event_add_nolock_()
2593 EVTHREAD_COND_WAIT(base->current_event_cond, base->th_base_lock); in event_add_nolock_()
2600 res = evmap_io_add_(base, ev->ev_fd, ev); in event_add_nolock_()
2602 res = evmap_signal_add_(base, (int)ev->ev_fd, ev); in event_add_nolock_()
2604 event_queue_insert_inserted(base, ev); in event_add_nolock_()
2635 event_queue_remove_timeout(base, ev); in event_add_nolock_()
2654 event_queue_remove_active(base, event_to_event_callback(ev)); in event_add_nolock_()
2657 gettime(base, &now); in event_add_nolock_()
2659 common_timeout = is_common_timeout(tv, base); in event_add_nolock_()
2661 was_common = is_common_timeout(&ev->ev_timeout, base); in event_add_nolock_()
2682 event_queue_reinsert_timeout(base, ev, was_common, common_timeout, old_timeout_idx); in event_add_nolock_()
2684 event_queue_insert_timeout(base, ev); in event_add_nolock_()
2689 get_common_timeout_list(base, &ev->ev_timeout); in event_add_nolock_()
2703 else if ((top = min_heap_top_(&base->timeheap)) != NULL && in event_add_nolock_()
2710 if (res != -1 && notify && EVBASE_NEED_NOTIFY(base)) in event_add_nolock_()
2711 evthread_notify_base(base); in event_add_nolock_()
2763 struct event_base *base; in event_del_nolock_() local
2769 /* An event without a base has not been added */ in event_del_nolock_()
2787 base = ev->ev_base; in event_del_nolock_()
2790 base->current_event == event_to_event_callback(ev) && in event_del_nolock_()
2791 !EVBASE_IN_THREAD(base) && in event_del_nolock_()
2793 ++base->current_event_waiters; in event_del_nolock_()
2794 EVTHREAD_COND_WAIT(base->current_event_cond, base->th_base_lock); in event_del_nolock_()
2816 event_queue_remove_timeout(base, ev); in event_del_nolock_()
2820 event_queue_remove_active(base, event_to_event_callback(ev)); in event_del_nolock_()
2822 event_queue_remove_active_later(base, event_to_event_callback(ev)); in event_del_nolock_()
2825 event_queue_remove_inserted(base, ev); in event_del_nolock_()
2827 res = evmap_io_del_(base, ev->ev_fd, ev); in event_del_nolock_()
2829 res = evmap_signal_del_(base, (int)ev->ev_fd, ev); in event_del_nolock_()
2838 if (res != -1 && notify && EVBASE_NEED_NOTIFY(base)) in event_del_nolock_()
2839 evthread_notify_base(base); in event_del_nolock_()
2867 struct event_base *base; in event_active_nolock_() local
2872 base = ev->ev_base; in event_active_nolock_()
2873 EVENT_BASE_ASSERT_LOCKED(base); in event_active_nolock_()
2897 if (ev->ev_pri < base->event_running_priority) in event_active_nolock_()
2898 base->event_continue = 1; in event_active_nolock_()
2902 if (base->current_event == event_to_event_callback(ev) && in event_active_nolock_()
2903 !EVBASE_IN_THREAD(base)) { in event_active_nolock_()
2904 ++base->current_event_waiters; in event_active_nolock_()
2905 EVTHREAD_COND_WAIT(base->current_event_cond, base->th_base_lock); in event_active_nolock_()
2912 event_callback_activate_nolock_(base, event_to_event_callback(ev)); in event_active_nolock_()
2926 struct event_base *base = ev->ev_base; in event_active_later_nolock_() local
2927 EVENT_BASE_ASSERT_LOCKED(base); in event_active_later_nolock_()
2937 event_callback_activate_later_nolock_(base, event_to_event_callback(ev)); in event_active_later_nolock_()
2941 event_callback_activate_(struct event_base *base, in event_callback_activate_() argument
2945 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_callback_activate_()
2946 r = event_callback_activate_nolock_(base, evcb); in event_callback_activate_()
2947 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_callback_activate_()
2952 event_callback_activate_nolock_(struct event_base *base, in event_callback_activate_nolock_() argument
2964 event_queue_remove_active_later(base, evcb); in event_callback_activate_nolock_()
2973 event_queue_insert_active(base, evcb); in event_callback_activate_nolock_()
2975 if (EVBASE_NEED_NOTIFY(base)) in event_callback_activate_nolock_()
2976 evthread_notify_base(base); in event_callback_activate_nolock_()
2982 event_callback_activate_later_nolock_(struct event_base *base, in event_callback_activate_later_nolock_() argument
2988 event_queue_insert_active_later(base, evcb); in event_callback_activate_later_nolock_()
2989 if (EVBASE_NEED_NOTIFY(base)) in event_callback_activate_later_nolock_()
2990 evthread_notify_base(base); in event_callback_activate_later_nolock_()
2995 event_callback_init_(struct event_base *base, in event_callback_init_() argument
2999 cb->evcb_pri = base->nactivequeues - 1; in event_callback_init_()
3003 event_callback_cancel_(struct event_base *base, in event_callback_cancel_() argument
3007 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_callback_cancel_()
3008 r = event_callback_cancel_nolock_(base, evcb, 0); in event_callback_cancel_()
3009 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_callback_cancel_()
3014 event_callback_cancel_nolock_(struct event_base *base, in event_callback_cancel_nolock_() argument
3031 event_queue_remove_active(base, evcb); in event_callback_cancel_nolock_()
3034 event_queue_remove_active_later(base, evcb); in event_callback_cancel_nolock_()
3060 event_deferred_cb_cancel_(struct event_base *base, struct event_callback *cb) in event_deferred_cb_cancel_() argument
3062 if (!base) in event_deferred_cb_cancel_()
3063 base = current_base; in event_deferred_cb_cancel_()
3064 event_callback_cancel_(base, cb); in event_deferred_cb_cancel_()
3069 event_deferred_cb_schedule_(struct event_base *base, struct event_callback *cb) in event_deferred_cb_schedule_() argument
3072 if (!base) in event_deferred_cb_schedule_()
3073 base = current_base; in event_deferred_cb_schedule_()
3074 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_deferred_cb_schedule_()
3075 if (base->n_deferreds_queued > MAX_DEFERREDS_QUEUED) { in event_deferred_cb_schedule_()
3076 r = event_callback_activate_later_nolock_(base, cb); in event_deferred_cb_schedule_()
3078 r = event_callback_activate_nolock_(base, cb); in event_deferred_cb_schedule_()
3080 ++base->n_deferreds_queued; in event_deferred_cb_schedule_()
3083 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_deferred_cb_schedule_()
3088 timeout_next(struct event_base *base, struct timeval **tv_p) in timeout_next() argument
3096 ev = min_heap_top_(&base->timeheap); in timeout_next()
3104 if (gettime(base, &now) == -1) { in timeout_next()
3126 timeout_process(struct event_base *base) in timeout_process() argument
3132 if (min_heap_empty_(&base->timeheap)) { in timeout_process()
3136 gettime(base, &now); in timeout_process()
3138 while ((ev = min_heap_top_(&base->timeheap))) { in timeout_process()
3163 base->event_count--/++;
3165 #define DECR_EVENT_COUNT(base,flags) \ argument
3166 ((base)->event_count -= (~((flags) >> 4) & 1))
3167 #define INCR_EVENT_COUNT(base,flags) do { \ argument
3168 ((base)->event_count += (~((flags) >> 4) & 1)); \
3169 MAX_EVENT_COUNT((base)->event_count_max, (base)->event_count); \
3173 event_queue_remove_inserted(struct event_base *base, struct event *ev) in event_queue_remove_inserted() argument
3175 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_remove_inserted()
3181 DECR_EVENT_COUNT(base, ev->ev_flags); in event_queue_remove_inserted()
3185 event_queue_remove_active(struct event_base *base, struct event_callback *evcb) in event_queue_remove_active() argument
3187 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_remove_active()
3193 DECR_EVENT_COUNT(base, evcb->evcb_flags); in event_queue_remove_active()
3195 base->event_count_active--; in event_queue_remove_active()
3197 TAILQ_REMOVE(&base->activequeues[evcb->evcb_pri], in event_queue_remove_active()
3201 event_queue_remove_active_later(struct event_base *base, struct event_callback *evcb) in event_queue_remove_active_later() argument
3203 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_remove_active_later()
3209 DECR_EVENT_COUNT(base, evcb->evcb_flags); in event_queue_remove_active_later()
3211 base->event_count_active--; in event_queue_remove_active_later()
3213 TAILQ_REMOVE(&base->active_later_queue, evcb, evcb_active_next); in event_queue_remove_active_later()
3216 event_queue_remove_timeout(struct event_base *base, struct event *ev) in event_queue_remove_timeout() argument
3218 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_remove_timeout()
3224 DECR_EVENT_COUNT(base, ev->ev_flags); in event_queue_remove_timeout()
3227 if (is_common_timeout(&ev->ev_timeout, base)) { in event_queue_remove_timeout()
3229 get_common_timeout_list(base, &ev->ev_timeout); in event_queue_remove_timeout()
3233 min_heap_erase_(&base->timeheap, ev); in event_queue_remove_timeout()
3240 event_queue_reinsert_timeout(struct event_base *base, struct event *ev, in event_queue_reinsert_timeout() argument
3245 event_queue_insert_timeout(base, ev); in event_queue_reinsert_timeout()
3251 ctl = base->common_timeout_queues[old_timeout_idx]; in event_queue_reinsert_timeout()
3254 ctl = get_common_timeout_list(base, &ev->ev_timeout); in event_queue_reinsert_timeout()
3258 ctl = base->common_timeout_queues[old_timeout_idx]; in event_queue_reinsert_timeout()
3261 min_heap_push_(&base->timeheap, ev); in event_queue_reinsert_timeout()
3264 min_heap_erase_(&base->timeheap, ev); in event_queue_reinsert_timeout()
3265 ctl = get_common_timeout_list(base, &ev->ev_timeout); in event_queue_reinsert_timeout()
3269 min_heap_adjust_(&base->timeheap, ev); in event_queue_reinsert_timeout()
3310 event_queue_insert_inserted(struct event_base *base, struct event *ev) in event_queue_insert_inserted() argument
3312 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_insert_inserted()
3320 INCR_EVENT_COUNT(base, ev->ev_flags); in event_queue_insert_inserted()
3326 event_queue_insert_active(struct event_base *base, struct event_callback *evcb) in event_queue_insert_active() argument
3328 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_insert_active()
3335 INCR_EVENT_COUNT(base, evcb->evcb_flags); in event_queue_insert_active()
3339 base->event_count_active++; in event_queue_insert_active()
3340 MAX_EVENT_COUNT(base->event_count_active_max, base->event_count_active); in event_queue_insert_active()
3341 EVUTIL_ASSERT(evcb->evcb_pri < base->nactivequeues); in event_queue_insert_active()
3342 TAILQ_INSERT_TAIL(&base->activequeues[evcb->evcb_pri], in event_queue_insert_active()
3347 event_queue_insert_active_later(struct event_base *base, struct event_callback *evcb) in event_queue_insert_active_later() argument
3349 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_insert_active_later()
3355 INCR_EVENT_COUNT(base, evcb->evcb_flags); in event_queue_insert_active_later()
3357 base->event_count_active++; in event_queue_insert_active_later()
3358 MAX_EVENT_COUNT(base->event_count_active_max, base->event_count_active); in event_queue_insert_active_later()
3359 EVUTIL_ASSERT(evcb->evcb_pri < base->nactivequeues); in event_queue_insert_active_later()
3360 TAILQ_INSERT_TAIL(&base->active_later_queue, evcb, evcb_active_next); in event_queue_insert_active_later()
3364 event_queue_insert_timeout(struct event_base *base, struct event *ev) in event_queue_insert_timeout() argument
3366 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_insert_timeout()
3374 INCR_EVENT_COUNT(base, ev->ev_flags); in event_queue_insert_timeout()
3378 if (is_common_timeout(&ev->ev_timeout, base)) { in event_queue_insert_timeout()
3380 get_common_timeout_list(base, &ev->ev_timeout); in event_queue_insert_timeout()
3383 min_heap_push_(&base->timeheap, ev); in event_queue_insert_timeout()
3388 event_queue_make_later_events_active(struct event_base *base) in event_queue_make_later_events_active() argument
3391 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_make_later_events_active()
3393 while ((evcb = TAILQ_FIRST(&base->active_later_queue))) { in event_queue_make_later_events_active()
3394 TAILQ_REMOVE(&base->active_later_queue, evcb, evcb_active_next); in event_queue_make_later_events_active()
3396 EVUTIL_ASSERT(evcb->evcb_pri < base->nactivequeues); in event_queue_make_later_events_active()
3397 TAILQ_INSERT_TAIL(&base->activequeues[evcb->evcb_pri], evcb, evcb_active_next); in event_queue_make_later_events_active()
3398 base->n_deferreds_queued += (evcb->evcb_closure == EV_CLOSURE_CB_SELF); in event_queue_make_later_events_active()
3536 struct event_base *base = arg; in evthread_notify_drain_eventfd() local
3542 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in evthread_notify_drain_eventfd()
3543 base->is_notify_pending = 0; in evthread_notify_drain_eventfd()
3544 EVBASE_RELEASE_LOCK(base, th_base_lock); in evthread_notify_drain_eventfd()
3552 struct event_base *base = arg; in evthread_notify_drain_default() local
3561 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in evthread_notify_drain_default()
3562 base->is_notify_pending = 0; in evthread_notify_drain_default()
3563 EVBASE_RELEASE_LOCK(base, th_base_lock); in evthread_notify_drain_default()
3567 evthread_make_base_notifiable(struct event_base *base) in evthread_make_base_notifiable() argument
3570 if (!base) in evthread_make_base_notifiable()
3573 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in evthread_make_base_notifiable()
3574 r = evthread_make_base_notifiable_nolock_(base); in evthread_make_base_notifiable()
3575 EVBASE_RELEASE_LOCK(base, th_base_lock); in evthread_make_base_notifiable()
3580 evthread_make_base_notifiable_nolock_(struct event_base *base) in evthread_make_base_notifiable_nolock_() argument
3585 if (base->th_notify_fn != NULL) { in evthread_make_base_notifiable_nolock_()
3586 /* The base is already notifiable: we're doing fine. */ in evthread_make_base_notifiable_nolock_()
3591 if (base->evsel == &kqops && event_kq_add_notify_event_(base) == 0) { in evthread_make_base_notifiable_nolock_()
3592 base->th_notify_fn = event_kq_notify_base_; in evthread_make_base_notifiable_nolock_()
3600 base->th_notify_fd[0] = evutil_eventfd_(0, in evthread_make_base_notifiable_nolock_()
3602 if (base->th_notify_fd[0] >= 0) { in evthread_make_base_notifiable_nolock_()
3603 base->th_notify_fd[1] = -1; in evthread_make_base_notifiable_nolock_()
3608 if (evutil_make_internal_pipe_(base->th_notify_fd) == 0) { in evthread_make_base_notifiable_nolock_()
3615 base->th_notify_fn = notify; in evthread_make_base_notifiable_nolock_()
3618 event_assign(&base->th_notify, base, base->th_notify_fd[0], in evthread_make_base_notifiable_nolock_()
3619 EV_READ|EV_PERSIST, cb, base); in evthread_make_base_notifiable_nolock_()
3622 base->th_notify.ev_flags |= EVLIST_INTERNAL; in evthread_make_base_notifiable_nolock_()
3623 event_priority_set(&base->th_notify, 0); in evthread_make_base_notifiable_nolock_()
3625 return event_add_nolock_(&base->th_notify, NULL, 0); in evthread_make_base_notifiable_nolock_()
3629 event_base_foreach_event_nolock_(struct event_base *base, in event_base_foreach_event_nolock_() argument
3637 if ((r = evmap_foreach_event_(base, fn, arg))) in event_base_foreach_event_nolock_()
3642 for (u = 0; u < base->timeheap.n; ++u) { in event_base_foreach_event_nolock_()
3643 ev = base->timeheap.p[u]; in event_base_foreach_event_nolock_()
3648 if ((r = fn(base, ev, arg))) in event_base_foreach_event_nolock_()
3654 for (i = 0; i < base->n_common_timeouts; ++i) { in event_base_foreach_event_nolock_()
3656 base->common_timeout_queues[i]; in event_base_foreach_event_nolock_()
3663 if ((r = fn(base, ev, arg))) in event_base_foreach_event_nolock_()
3670 for (i = 0; i < base->nactivequeues; ++i) { in event_base_foreach_event_nolock_()
3672 TAILQ_FOREACH(evcb, &base->activequeues[i], evcb_active_next) { in event_base_foreach_event_nolock_()
3680 if ((r = fn(base, ev, arg))) in event_base_foreach_event_nolock_()
3688 /* Helper for event_base_dump_events: called on each event in the event base;
3691 dump_inserted_event_fn(const struct event_base *base, const struct event *e, void *arg) in dump_inserted_event_fn() argument
3712 evutil_timeradd(&tv, &base->tv_clock_diff, &tv); in dump_inserted_event_fn()
3721 /* Helper for event_base_dump_events: called on each event in the event base;
3724 dump_active_event_fn(const struct event_base *base, const struct event *e, void *arg) in dump_active_event_fn() argument
3747 event_base_foreach_event(struct event_base *base, in event_base_foreach_event() argument
3751 if ((!fn) || (!base)) { in event_base_foreach_event()
3754 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_foreach_event()
3755 r = event_base_foreach_event_nolock_(base, fn, arg); in event_base_foreach_event()
3756 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_foreach_event()
3762 event_base_dump_events(struct event_base *base, FILE *output) in event_base_dump_events() argument
3764 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_dump_events()
3766 event_base_foreach_event_nolock_(base, dump_inserted_event_fn, output); in event_base_dump_events()
3769 event_base_foreach_event_nolock_(base, dump_active_event_fn, output); in event_base_dump_events()
3770 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_dump_events()
3774 event_base_active_by_fd(struct event_base *base, evutil_socket_t fd, short events) in event_base_active_by_fd() argument
3776 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_active_by_fd()
3777 evmap_io_active_(base, fd, events & (EV_READ|EV_WRITE|EV_CLOSED)); in event_base_active_by_fd()
3778 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_active_by_fd()
3782 event_base_active_by_signal(struct event_base *base, int sig) in event_base_active_by_signal() argument
3784 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_active_by_signal()
3785 evmap_signal_active_(base, sig, 1); in event_base_active_by_signal()
3786 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_active_by_signal()
3791 event_base_add_virtual_(struct event_base *base) in event_base_add_virtual_() argument
3793 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_add_virtual_()
3794 base->virtual_event_count++; in event_base_add_virtual_()
3795 MAX_EVENT_COUNT(base->virtual_event_count_max, base->virtual_event_count); in event_base_add_virtual_()
3796 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_add_virtual_()
3800 event_base_del_virtual_(struct event_base *base) in event_base_del_virtual_() argument
3802 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_del_virtual_()
3803 EVUTIL_ASSERT(base->virtual_event_count > 0); in event_base_del_virtual_()
3804 base->virtual_event_count--; in event_base_del_virtual_()
3805 if (base->virtual_event_count == 0 && EVBASE_NEED_NOTIFY(base)) in event_base_del_virtual_()
3806 evthread_notify_base(base); in event_base_del_virtual_()
3807 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_del_virtual_()
3876 event_base_assert_ok_(struct event_base *base) in event_base_assert_ok_() argument
3878 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_assert_ok_()
3879 event_base_assert_ok_nolock_(base); in event_base_assert_ok_()
3880 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_assert_ok_()
3884 event_base_assert_ok_nolock_(struct event_base *base) in event_base_assert_ok_nolock_() argument
3890 evmap_check_integrity_(base); in event_base_assert_ok_nolock_()
3893 for (i = 1; i < (int)base->timeheap.n; ++i) { in event_base_assert_ok_nolock_()
3896 ev = base->timeheap.p[i]; in event_base_assert_ok_nolock_()
3897 p_ev = base->timeheap.p[parent]; in event_base_assert_ok_nolock_()
3904 for (i = 0; i < base->n_common_timeouts; ++i) { in event_base_assert_ok_nolock_()
3905 struct common_timeout_list *ctl = base->common_timeout_queues[i]; in event_base_assert_ok_nolock_()
3914 EVUTIL_ASSERT(is_common_timeout(&ev->ev_timeout,base)); in event_base_assert_ok_nolock_()
3922 for (i = 0; i < base->nactivequeues; ++i) { in event_base_assert_ok_nolock_()
3924 EVUTIL_ASSERT_TAILQ_OK(&base->activequeues[i], event_callback, evcb_active_next); in event_base_assert_ok_nolock_()
3925 TAILQ_FOREACH(evcb, &base->activequeues[i], evcb_active_next) { in event_base_assert_ok_nolock_()
3934 TAILQ_FOREACH(evcb, &base->active_later_queue, evcb_active_next) { in event_base_assert_ok_nolock_()
3939 EVUTIL_ASSERT(count == base->event_count_active); in event_base_assert_ok_nolock_()