Lines Matching full:base
146 static void event_queue_make_later_events_active(struct event_base *base);
148 static int evthread_make_base_notifiable_nolock_(struct event_base *base);
166 static int evthread_notify_base(struct event_base *base);
400 #define EVENT_BASE_ASSERT_LOCKED(base) \ argument
401 EVLOCK_ASSERT_LOCKED((base)->th_base_lock)
407 /** Set 'tp' to the current time according to 'base'. We must hold the lock
408 * on 'base'. If there is a cached time, return it. Otherwise, use
413 gettime(struct event_base *base, struct timeval *tp) in gettime() argument
415 EVENT_BASE_ASSERT_LOCKED(base); in gettime()
417 if (base->tv_cache.tv_sec) { in gettime()
418 *tp = base->tv_cache; in gettime()
422 if (evutil_gettime_monotonic_(&base->monotonic_timer, tp) == -1) { in gettime()
426 if (base->last_updated_clock_diff + CLOCK_SYNC_INTERVAL in gettime()
430 evutil_timersub(&tv, tp, &base->tv_clock_diff); in gettime()
431 base->last_updated_clock_diff = tp->tv_sec; in gettime()
438 event_base_gettimeofday_cached(struct event_base *base, struct timeval *tv) in event_base_gettimeofday_cached() argument
441 if (!base) { in event_base_gettimeofday_cached()
442 base = current_base; in event_base_gettimeofday_cached()
447 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_gettimeofday_cached()
448 if (base->tv_cache.tv_sec == 0) { in event_base_gettimeofday_cached()
451 evutil_timeradd(&base->tv_cache, &base->tv_clock_diff, tv); in event_base_gettimeofday_cached()
454 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_gettimeofday_cached()
458 /** Make 'base' have no current cached time. */
460 clear_time_cache(struct event_base *base) in clear_time_cache() argument
462 base->tv_cache.tv_sec = 0; in clear_time_cache()
465 /** Replace the cached time in 'base' with the current time. */
467 update_time_cache(struct event_base *base) in update_time_cache() argument
469 base->tv_cache.tv_sec = 0; in update_time_cache()
470 if (!(base->flags & EVENT_BASE_FLAG_NO_CACHE_TIME)) in update_time_cache()
471 gettime(base, &base->tv_cache); in update_time_cache()
475 event_base_update_cache_time(struct event_base *base) in event_base_update_cache_time() argument
478 if (!base) { in event_base_update_cache_time()
479 base = current_base; in event_base_update_cache_time()
484 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_update_cache_time()
485 if (base->running_loop) in event_base_update_cache_time()
486 update_time_cache(base); in event_base_update_cache_time()
487 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_update_cache_time()
507 struct event_base *base = event_base_new_with_config(NULL); in event_init() local
509 if (base == NULL) { in event_init()
514 current_base = base; in event_init()
516 return (base); in event_init()
522 struct event_base *base = NULL; in event_base_new() local
525 base = event_base_new_with_config(cfg); in event_base_new()
528 return base; in event_base_new()
564 event_base_get_features(const struct event_base *base) in event_base_get_features() argument
566 return base->evsel->features; in event_base_get_features()
608 struct event_base *base; in event_base_new_with_config() local
615 if ((base = mm_calloc(1, sizeof(struct event_base))) == NULL) { in event_base_new_with_config()
621 base->flags = cfg->flags; in event_base_new_with_config()
634 base->flags |= EVENT_BASE_FLAG_PRECISE_TIMER; in event_base_new_with_config()
638 evutil_configure_monotonic_time_(&base->monotonic_timer, flags); in event_base_new_with_config()
640 gettime(base, &tmp); in event_base_new_with_config()
643 min_heap_ctor_(&base->timeheap); in event_base_new_with_config()
645 base->sig.ev_signal_pair[0] = -1; in event_base_new_with_config()
646 base->sig.ev_signal_pair[1] = -1; in event_base_new_with_config()
647 base->th_notify_fd[0] = -1; in event_base_new_with_config()
648 base->th_notify_fd[1] = -1; in event_base_new_with_config()
650 TAILQ_INIT(&base->active_later_queue); in event_base_new_with_config()
652 evmap_io_initmap_(&base->io); in event_base_new_with_config()
653 evmap_signal_initmap_(&base->sigmap); in event_base_new_with_config()
654 event_changelist_init_(&base->changelist); in event_base_new_with_config()
656 base->evbase = NULL; in event_base_new_with_config()
659 memcpy(&base->max_dispatch_time, in event_base_new_with_config()
661 base->limit_callbacks_after_prio = in event_base_new_with_config()
664 base->max_dispatch_time.tv_sec = -1; in event_base_new_with_config()
665 base->limit_callbacks_after_prio = 1; in event_base_new_with_config()
668 base->max_dispatch_callbacks = cfg->max_dispatch_callbacks; in event_base_new_with_config()
670 base->max_dispatch_callbacks = INT_MAX; in event_base_new_with_config()
672 if (base->max_dispatch_callbacks == INT_MAX && in event_base_new_with_config()
673 base->max_dispatch_time.tv_sec == -1) in event_base_new_with_config()
674 base->limit_callbacks_after_prio = INT_MAX; in event_base_new_with_config()
676 for (i = 0; eventops[i] && !base->evbase; i++) { in event_base_new_with_config()
692 base->evsel = eventops[i]; in event_base_new_with_config()
694 base->evbase = base->evsel->init(base); in event_base_new_with_config()
697 if (base->evbase == NULL) { in event_base_new_with_config()
700 base->evsel = NULL; in event_base_new_with_config()
701 event_base_free(base); in event_base_new_with_config()
706 event_msgx("libevent using: %s", base->evsel->name); in event_base_new_with_config()
709 if (event_base_priority_init(base, 1) < 0) { in event_base_new_with_config()
710 event_base_free(base); in event_base_new_with_config()
724 EVTHREAD_ALLOC_LOCK(base->th_base_lock, 0); in event_base_new_with_config()
725 EVTHREAD_ALLOC_COND(base->current_event_cond); in event_base_new_with_config()
726 r = evthread_make_base_notifiable(base); in event_base_new_with_config()
728 event_warnx("%s: Unable to make base notifiable.", __func__); in event_base_new_with_config()
729 event_base_free(base); in event_base_new_with_config()
737 event_base_start_iocp_(base, cfg->n_cpus_hint); in event_base_new_with_config()
740 return (base); in event_base_new_with_config()
744 event_base_start_iocp_(struct event_base *base, int n_cpus) in event_base_start_iocp_() argument
747 if (base->iocp) in event_base_start_iocp_()
749 base->iocp = event_iocp_port_launch_(n_cpus); in event_base_start_iocp_()
750 if (!base->iocp) { in event_base_start_iocp_()
761 event_base_stop_iocp_(struct event_base *base) in event_base_stop_iocp_() argument
766 if (!base->iocp) in event_base_stop_iocp_()
768 rv = event_iocp_shutdown_(base->iocp, -1); in event_base_stop_iocp_()
770 base->iocp = NULL; in event_base_stop_iocp_()
775 event_base_cancel_single_callback_(struct event_base *base, in event_base_cancel_single_callback_() argument
788 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_cancel_single_callback_()
789 event_callback_cancel_nolock_(base, evcb, 1); in event_base_cancel_single_callback_()
790 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_cancel_single_callback_()
814 static int event_base_free_queues_(struct event_base *base, int run_finalizers) in event_base_free_queues_() argument
818 for (i = 0; i < base->nactivequeues; ++i) { in event_base_free_queues_()
820 for (evcb = TAILQ_FIRST(&base->activequeues[i]); evcb; ) { in event_base_free_queues_()
822 deleted += event_base_cancel_single_callback_(base, evcb, run_finalizers); in event_base_free_queues_()
829 while ((evcb = TAILQ_FIRST(&base->active_later_queue))) { in event_base_free_queues_()
830 deleted += event_base_cancel_single_callback_(base, evcb, run_finalizers); in event_base_free_queues_()
838 event_base_free_(struct event_base *base, int run_finalizers) in event_base_free_() argument
843 * the base, then the contending thread will be very sad soon. */ in event_base_free_()
847 if (base == NULL && current_base) in event_base_free_()
848 base = current_base; in event_base_free_()
850 if (base == NULL) { in event_base_free_()
851 event_warnx("%s: no base to free", __func__); in event_base_free_()
857 event_base_stop_iocp_(base); in event_base_free_()
861 if (base->th_notify_fd[0] != -1) { in event_base_free_()
862 event_del(&base->th_notify); in event_base_free_()
863 EVUTIL_CLOSESOCKET(base->th_notify_fd[0]); in event_base_free_()
864 if (base->th_notify_fd[1] != -1) in event_base_free_()
865 EVUTIL_CLOSESOCKET(base->th_notify_fd[1]); in event_base_free_()
866 base->th_notify_fd[0] = -1; in event_base_free_()
867 base->th_notify_fd[1] = -1; in event_base_free_()
868 event_debug_unassign(&base->th_notify); in event_base_free_()
872 evmap_delete_all_(base); in event_base_free_()
874 while ((ev = min_heap_top_(&base->timeheap)) != NULL) { in event_base_free_()
878 for (i = 0; i < base->n_common_timeouts; ++i) { in event_base_free_()
880 base->common_timeout_queues[i]; in event_base_free_()
894 if (base->common_timeout_queues) in event_base_free_()
895 mm_free(base->common_timeout_queues); in event_base_free_()
906 int i = event_base_free_queues_(base, run_finalizers); in event_base_free_()
915 event_debug(("%s: %d events were still set in base", in event_base_free_()
918 while (LIST_FIRST(&base->once_events)) { in event_base_free_()
919 struct event_once *eonce = LIST_FIRST(&base->once_events); in event_base_free_()
924 if (base->evsel != NULL && base->evsel->dealloc != NULL) in event_base_free_()
925 base->evsel->dealloc(base); in event_base_free_()
927 for (i = 0; i < base->nactivequeues; ++i) in event_base_free_()
928 EVUTIL_ASSERT(TAILQ_EMPTY(&base->activequeues[i])); in event_base_free_()
930 EVUTIL_ASSERT(min_heap_empty_(&base->timeheap)); in event_base_free_()
931 min_heap_dtor_(&base->timeheap); in event_base_free_()
933 mm_free(base->activequeues); in event_base_free_()
935 evmap_io_clear_(&base->io); in event_base_free_()
936 evmap_signal_clear_(&base->sigmap); in event_base_free_()
937 event_changelist_freemem_(&base->changelist); in event_base_free_()
939 EVTHREAD_FREE_LOCK(base->th_base_lock, 0); in event_base_free_()
940 EVTHREAD_FREE_COND(base->current_event_cond); in event_base_free_()
943 if (base == current_base) in event_base_free_()
945 mm_free(base); in event_base_free_()
949 event_base_free_nofinalize(struct event_base *base) in event_base_free_nofinalize() argument
951 event_base_free_(base, 0); in event_base_free_nofinalize()
955 event_base_free(struct event_base *base) in event_base_free() argument
957 event_base_free_(base, 1); in event_base_free()
979 /* reinitialize the event base after a fork */
981 event_reinit(struct event_base *base) in event_reinit() argument
988 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_reinit()
990 evsel = base->evsel; in event_reinit()
1002 base->evsel = &nil_eventop; in event_reinit()
1011 if (base->sig.ev_signal_added) { in event_reinit()
1012 event_del_nolock_(&base->sig.ev_signal, EVENT_DEL_AUTOBLOCK); in event_reinit()
1013 event_debug_unassign(&base->sig.ev_signal); in event_reinit()
1014 memset(&base->sig.ev_signal, 0, sizeof(base->sig.ev_signal)); in event_reinit()
1016 base->sig.ev_signal_added = 0; in event_reinit()
1018 if (base->sig.ev_signal_pair[0] != -1) in event_reinit()
1019 EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[0]); in event_reinit()
1020 if (base->sig.ev_signal_pair[1] != -1) in event_reinit()
1021 EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[1]); in event_reinit()
1022 if (base->th_notify_fn != NULL) { in event_reinit()
1024 base->th_notify_fn = NULL; in event_reinit()
1026 if (base->th_notify_fd[0] != -1) { in event_reinit()
1027 event_del_nolock_(&base->th_notify, EVENT_DEL_AUTOBLOCK); in event_reinit()
1028 EVUTIL_CLOSESOCKET(base->th_notify_fd[0]); in event_reinit()
1029 if (base->th_notify_fd[1] != -1) in event_reinit()
1030 EVUTIL_CLOSESOCKET(base->th_notify_fd[1]); in event_reinit()
1031 base->th_notify_fd[0] = -1; in event_reinit()
1032 base->th_notify_fd[1] = -1; in event_reinit()
1033 event_debug_unassign(&base->th_notify); in event_reinit()
1037 base->evsel = evsel; in event_reinit()
1049 if (base->evsel->dealloc != NULL) in event_reinit()
1050 base->evsel->dealloc(base); in event_reinit()
1051 base->evbase = evsel->init(base); in event_reinit()
1052 if (base->evbase == NULL) { in event_reinit()
1062 event_changelist_freemem_(&base->changelist); in event_reinit()
1067 if (evmap_reinit_(base) < 0) in event_reinit()
1070 res = evsig_init_(base); in event_reinit()
1072 res = event_add_nolock_(&base->sig.ev_signal, NULL, 0); in event_reinit()
1074 base->sig.ev_signal_added = 1; in event_reinit()
1081 res = evthread_make_base_notifiable_nolock_(base); in event_reinit()
1084 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_reinit()
1090 event_gettime_monotonic(struct event_base *base, struct timeval *tv) in event_gettime_monotonic() argument
1094 if (base && tv) { in event_gettime_monotonic()
1095 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_gettime_monotonic()
1096 rv = evutil_gettime_monotonic_(&(base->monotonic_timer), tv); in event_gettime_monotonic()
1097 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_gettime_monotonic()
1240 event_base_priority_init(struct event_base *base, int npriorities) in event_base_priority_init() argument
1245 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_priority_init()
1247 if (N_ACTIVE_CALLBACKS(base) || npriorities < 1 in event_base_priority_init()
1251 if (npriorities == base->nactivequeues) in event_base_priority_init()
1254 if (base->nactivequeues) { in event_base_priority_init()
1255 mm_free(base->activequeues); in event_base_priority_init()
1256 base->nactivequeues = 0; in event_base_priority_init()
1260 base->activequeues = (struct evcallback_list *) in event_base_priority_init()
1262 if (base->activequeues == NULL) { in event_base_priority_init()
1266 base->nactivequeues = npriorities; in event_base_priority_init()
1268 for (i = 0; i < base->nactivequeues; ++i) { in event_base_priority_init()
1269 TAILQ_INIT(&base->activequeues[i]); in event_base_priority_init()
1275 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_priority_init()
1280 event_base_get_npriorities(struct event_base *base) in event_base_get_npriorities() argument
1284 if (base == NULL) in event_base_get_npriorities()
1285 base = current_base; in event_base_get_npriorities()
1287 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_get_npriorities()
1288 n = base->nactivequeues; in event_base_get_npriorities()
1289 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_get_npriorities()
1294 event_base_get_num_events(struct event_base *base, unsigned int type) in event_base_get_num_events() argument
1298 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_get_num_events()
1301 r += base->event_count_active; in event_base_get_num_events()
1304 r += base->virtual_event_count; in event_base_get_num_events()
1307 r += base->event_count; in event_base_get_num_events()
1309 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_get_num_events()
1315 event_base_get_max_events(struct event_base *base, unsigned int type, int clear) in event_base_get_max_events() argument
1319 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_get_max_events()
1322 r += base->event_count_active_max; in event_base_get_max_events()
1324 base->event_count_active_max = 0; in event_base_get_max_events()
1328 r += base->virtual_event_count_max; in event_base_get_max_events()
1330 base->virtual_event_count_max = 0; in event_base_get_max_events()
1334 r += base->event_count_max; in event_base_get_max_events()
1336 base->event_count_max = 0; in event_base_get_max_events()
1339 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_get_max_events()
1346 event_haveevents(struct event_base *base) in event_haveevents() argument
1349 return (base->virtual_event_count > 0 || base->event_count > 0); in event_haveevents()
1354 event_signal_closure(struct event_base *base, struct event *ev) in event_signal_closure() argument
1363 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_signal_closure()
1371 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_signal_closure()
1372 should_break = base->event_break; in event_signal_closure()
1373 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_signal_closure()
1406 /** Return true iff if 'tv' is a common timeout in 'base' */
1409 const struct event_base *base) in is_common_timeout() argument
1415 return idx < base->n_common_timeouts; in is_common_timeout()
1430 get_common_timeout_list(struct event_base *base, const struct timeval *tv) in get_common_timeout_list() argument
1432 return base->common_timeout_queues[COMMON_TIMEOUT_IDX(tv)]; in get_common_timeout_list()
1438 struct event_base *base)
1441 &get_common_timeout_list(base, tv)->duration;
1466 struct event_base *base = ctl->base; in common_timeout_callback() local
1468 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in common_timeout_callback()
1469 gettime(base, &now); in common_timeout_callback()
1481 EVBASE_RELEASE_LOCK(base, th_base_lock); in common_timeout_callback()
1487 event_base_init_common_timeout(struct event_base *base, in event_base_init_common_timeout() argument
1495 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_init_common_timeout()
1498 if (is_common_timeout(duration, base)) in event_base_init_common_timeout()
1504 for (i = 0; i < base->n_common_timeouts; ++i) { in event_base_init_common_timeout()
1506 base->common_timeout_queues[i]; in event_base_init_common_timeout()
1510 EVUTIL_ASSERT(is_common_timeout(&ctl->duration, base)); in event_base_init_common_timeout()
1515 if (base->n_common_timeouts == MAX_COMMON_TIMEOUTS) { in event_base_init_common_timeout()
1521 if (base->n_common_timeouts_allocated == base->n_common_timeouts) { in event_base_init_common_timeout()
1522 int n = base->n_common_timeouts < 16 ? 16 : in event_base_init_common_timeout()
1523 base->n_common_timeouts*2; in event_base_init_common_timeout()
1525 mm_realloc(base->common_timeout_queues, in event_base_init_common_timeout()
1531 base->n_common_timeouts_allocated = n; in event_base_init_common_timeout()
1532 base->common_timeout_queues = newqueues; in event_base_init_common_timeout()
1543 (base->n_common_timeouts << COMMON_TIMEOUT_IDX_SHIFT); in event_base_init_common_timeout()
1544 evtimer_assign(&new_ctl->timeout_event, base, in event_base_init_common_timeout()
1548 new_ctl->base = base; in event_base_init_common_timeout()
1549 base->common_timeout_queues[base->n_common_timeouts++] = new_ctl; in event_base_init_common_timeout()
1554 EVUTIL_ASSERT(is_common_timeout(result, base)); in event_base_init_common_timeout()
1556 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_init_common_timeout()
1562 event_persist_closure(struct event_base *base, struct event *ev) in event_persist_closure() argument
1581 gettime(base, &now); in event_persist_closure()
1582 if (is_common_timeout(&ev->ev_timeout, base)) { in event_persist_closure()
1620 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_persist_closure()
1634 event_process_active_single_queue(struct event_base *base, in event_process_active_single_queue() argument
1649 event_queue_remove_active(base, evcb); in event_process_active_single_queue()
1660 event_queue_remove_active(base, evcb); in event_process_active_single_queue()
1670 base->current_event = evcb; in event_process_active_single_queue()
1672 base->current_event_waiters = 0; in event_process_active_single_queue()
1678 event_signal_closure(base, ev); in event_process_active_single_queue()
1682 event_persist_closure(base, ev); in event_process_active_single_queue()
1690 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_process_active_single_queue()
1696 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_process_active_single_queue()
1705 base->current_event = NULL; in event_process_active_single_queue()
1708 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_process_active_single_queue()
1717 base->current_event = NULL; in event_process_active_single_queue()
1719 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_process_active_single_queue()
1727 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_process_active_single_queue()
1728 base->current_event = NULL; in event_process_active_single_queue()
1730 if (base->current_event_waiters) { in event_process_active_single_queue()
1731 base->current_event_waiters = 0; in event_process_active_single_queue()
1732 EVTHREAD_COND_BROADCAST(base->current_event_cond); in event_process_active_single_queue()
1736 if (base->event_break) in event_process_active_single_queue()
1742 update_time_cache(base); in event_process_active_single_queue()
1743 gettime(base, &now); in event_process_active_single_queue()
1747 if (base->event_continue) in event_process_active_single_queue()
1760 event_process_active(struct event_base *base) in event_process_active() argument
1767 const int maxcb = base->max_dispatch_callbacks; in event_process_active()
1768 const int limit_after_prio = base->limit_callbacks_after_prio; in event_process_active()
1769 if (base->max_dispatch_time.tv_sec >= 0) { in event_process_active()
1770 update_time_cache(base); in event_process_active()
1771 gettime(base, &tv); in event_process_active()
1772 evutil_timeradd(&base->max_dispatch_time, &tv, &tv); in event_process_active()
1778 for (i = 0; i < base->nactivequeues; ++i) { in event_process_active()
1779 if (TAILQ_FIRST(&base->activequeues[i]) != NULL) { in event_process_active()
1780 base->event_running_priority = i; in event_process_active()
1781 activeq = &base->activequeues[i]; in event_process_active()
1783 c = event_process_active_single_queue(base, activeq, in event_process_active()
1786 c = event_process_active_single_queue(base, activeq, in event_process_active()
1799 base->event_running_priority = -1; in event_process_active()
1821 event_base_get_method(const struct event_base *base) in event_base_get_method() argument
1823 EVUTIL_ASSERT(base); in event_base_get_method()
1824 return (base->evsel->name); in event_base_get_method()
1832 struct event_base *base = arg; in event_loopexit_cb() local
1833 base->event_gotterm = 1; in event_loopexit_cb()
1923 event_base_loop(struct event_base *base, int flags) in event_base_loop() argument
1925 const struct eventop *evsel = base->evsel; in event_base_loop()
1932 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_loop()
1934 if (base->running_loop) { in event_base_loop()
1937 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_loop()
1941 base->running_loop = 1; in event_base_loop()
1943 clear_time_cache(base); in event_base_loop()
1945 if (base->sig.ev_signal_added && base->sig.ev_n_signals_added) in event_base_loop()
1946 evsig_set_base_(base); in event_base_loop()
1951 base->th_owner_id = EVTHREAD_GET_ID(); in event_base_loop()
1954 base->event_gotterm = base->event_break = 0; in event_base_loop()
1957 base->event_continue = 0; in event_base_loop()
1958 base->n_deferreds_queued = 0; in event_base_loop()
1961 if (base->event_gotterm) { in event_base_loop()
1965 if (base->event_break) { in event_base_loop()
1970 if (!N_ACTIVE_CALLBACKS(base) && !(flags & EVLOOP_NONBLOCK)) { in event_base_loop()
1971 timeout_next(base, &tv_p); in event_base_loop()
1982 !event_haveevents(base) && !N_ACTIVE_CALLBACKS(base)) { in event_base_loop()
1988 event_queue_make_later_events_active(base); in event_base_loop()
1990 clear_time_cache(base); in event_base_loop()
1992 res = evsel->dispatch(base, tv_p); in event_base_loop()
2001 update_time_cache(base); in event_base_loop()
2003 timeout_process(base); in event_base_loop()
2005 if (N_ACTIVE_CALLBACKS(base)) { in event_base_loop()
2006 int n = event_process_active(base); in event_base_loop()
2008 && N_ACTIVE_CALLBACKS(base) == 0 in event_base_loop()
2017 clear_time_cache(base); in event_base_loop()
2018 base->running_loop = 0; in event_base_loop()
2020 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_loop()
2051 event_base_once(struct event_base *base, evutil_socket_t fd, short events, in event_base_once() argument
2059 if (!base) in event_base_once()
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()
2094 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_once()
2104 LIST_INSERT_HEAD(&base->once_events, eonce, next_once); in event_base_once()
2106 EVBASE_RELEASE_LOCK(base, th_base_lock); 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
2115 if (!base) in event_assign()
2116 base = current_base; in event_assign()
2124 ev->ev_base = base; in event_assign()
2153 if (base != NULL) { in event_assign()
2155 ev->ev_pri = base->nactivequeues / 2; in event_assign()
2164 event_base_set(struct event_base *base, struct event *ev) in event_base_set() argument
2166 /* Only innocent events may be assigned to a different base */ in event_base_set()
2172 ev->ev_base = base; in event_base_set()
2173 ev->ev_pri = base->nactivequeues/2; in event_base_set()
2194 event_base_get_running_event(struct event_base *base) in event_base_get_running_event() argument
2197 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_get_running_event()
2198 if (EVBASE_IN_THREAD(base)) { in event_base_get_running_event()
2199 struct event_callback *evcb = base->current_event; in event_base_get_running_event()
2203 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_get_running_event()
2208 event_new(struct event_base *base, evutil_socket_t fd, short events, void (*cb)(evutil_socket_t, sh… in event_new() argument
2214 if (event_assign(ev, base, fd, events, cb, arg) < 0) { in event_new()
2247 event_finalize_nolock_(struct event_base *base, unsigned flags, struct event *ev, event_finalize_ca… in event_finalize_nolock_() argument
2264 struct event_base *base = ev->ev_base; in event_finalize_impl_() local
2265 if (EVUTIL_FAILURE_CHECK(!base)) { in event_finalize_impl_()
2270 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_finalize_impl_()
2271 r = event_finalize_nolock_(base, flags, ev, cb); in event_finalize_impl_()
2272 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_finalize_impl_()
2289 event_callback_finalize_nolock_(struct event_base *base, unsigned flags, struct event_callback *evc… in event_callback_finalize_nolock_() argument
2296 event_callback_cancel_nolock_(base, evcb, 0); /*XXX can this fail?*/ in event_callback_finalize_nolock_()
2301 event_callback_activate_nolock_(base, evcb); /* XXX can this really fail?*/ in event_callback_finalize_nolock_()
2306 event_callback_finalize_(struct event_base *base, unsigned flags, struct event_callback *evcb, void… in event_callback_finalize_() argument
2308 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_callback_finalize_()
2309 event_callback_finalize_nolock_(base, flags, evcb, cb); in event_callback_finalize_()
2310 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_callback_finalize_()
2317 event_callback_finalize_many_(struct event_base *base, int n_cbs, struct event_callback **evcbs, vo… in event_callback_finalize_many_() argument
2321 if (base == NULL) in event_callback_finalize_many_()
2322 base = current_base; in event_callback_finalize_many_()
2324 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_callback_finalize_many_()
2333 if (evcb == base->current_event) { in event_callback_finalize_many_()
2334 event_callback_finalize_nolock_(base, 0, evcb, cb); in event_callback_finalize_many_()
2337 event_callback_cancel_nolock_(base, evcb, 0); in event_callback_finalize_many_()
2343 event_callback_finalize_nolock_(base, 0, evcbs[0], cb); in event_callback_finalize_many_()
2346 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_callback_finalize_many_()
2507 evthread_notify_base_default(struct event_base *base) in evthread_notify_base_default() argument
2513 r = send(base->th_notify_fd[1], buf, 1, 0); in evthread_notify_base_default()
2515 r = write(base->th_notify_fd[1], buf, 1); in evthread_notify_base_default()
2524 evthread_notify_base_eventfd(struct event_base *base) in evthread_notify_base_eventfd() argument
2529 r = write(base->th_notify_fd[0], (void*) &msg, sizeof(msg)); in evthread_notify_base_eventfd()
2537 /** Tell the thread currently running the event_loop for base (if any) that it
2541 evthread_notify_base(struct event_base *base) in evthread_notify_base() argument
2543 EVENT_BASE_ASSERT_LOCKED(base); in evthread_notify_base()
2544 if (!base->th_notify_fn) in evthread_notify_base()
2546 if (base->is_notify_pending) in evthread_notify_base()
2548 base->is_notify_pending = 1; in evthread_notify_base()
2549 return base->th_notify_fn(base); in evthread_notify_base()
2557 struct event_base *base = ev->ev_base; in event_remove_timer_nolock_() local
2559 EVENT_BASE_ASSERT_LOCKED(base); in event_remove_timer_nolock_()
2566 event_queue_remove_timeout(base, ev); in event_remove_timer_nolock_()
2600 struct event_base *base = ev->ev_base; in event_add_nolock_() local
2604 EVENT_BASE_ASSERT_LOCKED(base); in event_add_nolock_()
2629 if (min_heap_reserve_(&base->timeheap, in event_add_nolock_()
2630 1 + min_heap_size_(&base->timeheap)) == -1) in event_add_nolock_()
2639 if (base->current_event == event_to_event_callback(ev) && in event_add_nolock_()
2641 && !EVBASE_IN_THREAD(base)) { in event_add_nolock_()
2642 ++base->current_event_waiters; in event_add_nolock_()
2643 EVTHREAD_COND_WAIT(base->current_event_cond, base->th_base_lock); in event_add_nolock_()
2650 res = evmap_io_add_(base, ev->ev_fd, ev); 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_()
2685 event_queue_remove_timeout(base, ev); in event_add_nolock_()
2704 event_queue_remove_active(base, event_to_event_callback(ev)); in event_add_nolock_()
2707 gettime(base, &now); in event_add_nolock_()
2709 common_timeout = is_common_timeout(tv, base); in event_add_nolock_()
2711 was_common = is_common_timeout(&ev->ev_timeout, base); 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_()
2753 else if ((top = min_heap_top_(&base->timeheap)) != NULL && in event_add_nolock_()
2760 if (res != -1 && notify && EVBASE_NEED_NOTIFY(base)) in event_add_nolock_()
2761 evthread_notify_base(base); in event_add_nolock_()
2772 struct event_base *base = ev->ev_base; in event_del_() local
2774 if (EVUTIL_FAILURE_CHECK(!base)) { in event_del_()
2779 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_del_()
2781 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_del_()
2812 struct event_base *base; in event_del_nolock_() local
2818 /* An event without a base has not been added */ in event_del_nolock_()
2831 base = ev->ev_base; in event_del_nolock_()
2851 event_queue_remove_timeout(base, ev); in event_del_nolock_()
2855 event_queue_remove_active(base, event_to_event_callback(ev)); in event_del_nolock_()
2857 event_queue_remove_active_later(base, event_to_event_callback(ev)); in event_del_nolock_()
2860 event_queue_remove_inserted(base, ev); 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_()
2870 /* If we do not have events, let's notify event base so it can in event_del_nolock_()
2872 if (!event_haveevents(base) && !N_ACTIVE_CALLBACKS(base)) in event_del_nolock_()
2877 if (res != -1 && notify && EVBASE_NEED_NOTIFY(base)) in event_del_nolock_()
2878 evthread_notify_base(base); in event_del_nolock_()
2889 base->current_event == event_to_event_callback(ev) && in event_del_nolock_()
2890 !EVBASE_IN_THREAD(base) && in event_del_nolock_()
2892 ++base->current_event_waiters; in event_del_nolock_()
2893 EVTHREAD_COND_WAIT(base->current_event_cond, base->th_base_lock); in event_del_nolock_()
2921 struct event_base *base; in event_active_nolock_() local
2926 base = ev->ev_base; in event_active_nolock_()
2927 EVENT_BASE_ASSERT_LOCKED(base); in event_active_nolock_()
2951 if (ev->ev_pri < base->event_running_priority) in event_active_nolock_()
2952 base->event_continue = 1; in event_active_nolock_()
2956 if (base->current_event == event_to_event_callback(ev) && in event_active_nolock_()
2957 !EVBASE_IN_THREAD(base)) { in event_active_nolock_()
2958 ++base->current_event_waiters; in event_active_nolock_()
2959 EVTHREAD_COND_WAIT(base->current_event_cond, base->th_base_lock); in event_active_nolock_()
2966 event_callback_activate_nolock_(base, event_to_event_callback(ev)); in event_active_nolock_()
2980 struct event_base *base = ev->ev_base; in event_active_later_nolock_() local
2981 EVENT_BASE_ASSERT_LOCKED(base); in event_active_later_nolock_()
2991 event_callback_activate_later_nolock_(base, event_to_event_callback(ev)); in event_active_later_nolock_()
2995 event_callback_activate_(struct event_base *base, in event_callback_activate_() argument
2999 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_callback_activate_()
3000 r = event_callback_activate_nolock_(base, evcb); in event_callback_activate_()
3001 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_callback_activate_()
3006 event_callback_activate_nolock_(struct event_base *base, in event_callback_activate_nolock_() argument
3019 event_queue_remove_active_later(base, evcb); in event_callback_activate_nolock_()
3028 event_queue_insert_active(base, evcb); in event_callback_activate_nolock_()
3030 if (EVBASE_NEED_NOTIFY(base)) in event_callback_activate_nolock_()
3031 evthread_notify_base(base); in event_callback_activate_nolock_()
3037 event_callback_activate_later_nolock_(struct event_base *base, in event_callback_activate_later_nolock_() argument
3043 event_queue_insert_active_later(base, evcb); in event_callback_activate_later_nolock_()
3044 if (EVBASE_NEED_NOTIFY(base)) in event_callback_activate_later_nolock_()
3045 evthread_notify_base(base); in event_callback_activate_later_nolock_()
3050 event_callback_init_(struct event_base *base, in event_callback_init_() argument
3054 cb->evcb_pri = base->nactivequeues - 1; in event_callback_init_()
3058 event_callback_cancel_(struct event_base *base, in event_callback_cancel_() argument
3062 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_callback_cancel_()
3063 r = event_callback_cancel_nolock_(base, evcb, 0); in event_callback_cancel_()
3064 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_callback_cancel_()
3069 event_callback_cancel_nolock_(struct event_base *base, in event_callback_cancel_nolock_() argument
3086 event_queue_remove_active(base, evcb); in event_callback_cancel_nolock_()
3089 event_queue_remove_active_later(base, evcb); in event_callback_cancel_nolock_()
3115 event_deferred_cb_cancel_(struct event_base *base, struct event_callback *cb) in event_deferred_cb_cancel_() argument
3117 if (!base) in event_deferred_cb_cancel_()
3118 base = current_base; in event_deferred_cb_cancel_()
3119 event_callback_cancel_(base, cb); in event_deferred_cb_cancel_()
3124 event_deferred_cb_schedule_(struct event_base *base, struct event_callback *cb) in event_deferred_cb_schedule_() argument
3127 if (!base) in event_deferred_cb_schedule_()
3128 base = current_base; in event_deferred_cb_schedule_()
3129 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_deferred_cb_schedule_()
3130 if (base->n_deferreds_queued > MAX_DEFERREDS_QUEUED) { in event_deferred_cb_schedule_()
3131 r = event_callback_activate_later_nolock_(base, cb); in event_deferred_cb_schedule_()
3133 r = event_callback_activate_nolock_(base, cb); in event_deferred_cb_schedule_()
3135 ++base->n_deferreds_queued; in event_deferred_cb_schedule_()
3138 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_deferred_cb_schedule_()
3143 timeout_next(struct event_base *base, struct timeval **tv_p) in timeout_next() argument
3151 ev = min_heap_top_(&base->timeheap); in timeout_next()
3159 if (gettime(base, &now) == -1) { in timeout_next()
3181 timeout_process(struct event_base *base) in timeout_process() argument
3187 if (min_heap_empty_(&base->timeheap)) { in timeout_process()
3191 gettime(base, &now); in timeout_process()
3193 while ((ev = min_heap_top_(&base->timeheap))) { in timeout_process()
3214 base->event_count--/++;
3216 #define DECR_EVENT_COUNT(base,flags) \ argument
3217 ((base)->event_count -= !((flags) & EVLIST_INTERNAL))
3218 #define INCR_EVENT_COUNT(base,flags) do { \ argument
3219 ((base)->event_count += !((flags) & EVLIST_INTERNAL)); \
3220 MAX_EVENT_COUNT((base)->event_count_max, (base)->event_count); \
3224 event_queue_remove_inserted(struct event_base *base, struct event *ev) in event_queue_remove_inserted() argument
3226 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_remove_inserted()
3232 DECR_EVENT_COUNT(base, ev->ev_flags); in event_queue_remove_inserted()
3236 event_queue_remove_active(struct event_base *base, struct event_callback *evcb) in event_queue_remove_active() argument
3238 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_remove_active()
3244 DECR_EVENT_COUNT(base, evcb->evcb_flags); in event_queue_remove_active()
3246 base->event_count_active--; in event_queue_remove_active()
3248 TAILQ_REMOVE(&base->activequeues[evcb->evcb_pri], in event_queue_remove_active()
3252 event_queue_remove_active_later(struct event_base *base, struct event_callback *evcb) in event_queue_remove_active_later() argument
3254 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_remove_active_later()
3260 DECR_EVENT_COUNT(base, evcb->evcb_flags); in event_queue_remove_active_later()
3262 base->event_count_active--; in event_queue_remove_active_later()
3264 TAILQ_REMOVE(&base->active_later_queue, evcb, evcb_active_next); in event_queue_remove_active_later()
3267 event_queue_remove_timeout(struct event_base *base, struct event *ev) in event_queue_remove_timeout() argument
3269 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_remove_timeout()
3275 DECR_EVENT_COUNT(base, ev->ev_flags); 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()
3284 min_heap_erase_(&base->timeheap, ev); in event_queue_remove_timeout()
3291 event_queue_reinsert_timeout(struct event_base *base, struct event *ev, in event_queue_reinsert_timeout() argument
3296 event_queue_insert_timeout(base, ev); in event_queue_reinsert_timeout()
3302 ctl = base->common_timeout_queues[old_timeout_idx]; in event_queue_reinsert_timeout()
3305 ctl = get_common_timeout_list(base, &ev->ev_timeout); in event_queue_reinsert_timeout()
3309 ctl = base->common_timeout_queues[old_timeout_idx]; 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()
3320 min_heap_adjust_(&base->timeheap, ev); in event_queue_reinsert_timeout()
3361 event_queue_insert_inserted(struct event_base *base, struct event *ev) in event_queue_insert_inserted() argument
3363 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_insert_inserted()
3371 INCR_EVENT_COUNT(base, ev->ev_flags); in event_queue_insert_inserted()
3377 event_queue_insert_active(struct event_base *base, struct event_callback *evcb) in event_queue_insert_active() argument
3379 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_insert_active()
3386 INCR_EVENT_COUNT(base, evcb->evcb_flags); in event_queue_insert_active()
3390 base->event_count_active++; in event_queue_insert_active()
3391 MAX_EVENT_COUNT(base->event_count_active_max, base->event_count_active); in event_queue_insert_active()
3392 EVUTIL_ASSERT(evcb->evcb_pri < base->nactivequeues); in event_queue_insert_active()
3393 TAILQ_INSERT_TAIL(&base->activequeues[evcb->evcb_pri], in event_queue_insert_active()
3398 event_queue_insert_active_later(struct event_base *base, struct event_callback *evcb) in event_queue_insert_active_later() argument
3400 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_insert_active_later()
3406 INCR_EVENT_COUNT(base, evcb->evcb_flags); in event_queue_insert_active_later()
3408 base->event_count_active++; in event_queue_insert_active_later()
3409 MAX_EVENT_COUNT(base->event_count_active_max, base->event_count_active); in event_queue_insert_active_later()
3410 EVUTIL_ASSERT(evcb->evcb_pri < base->nactivequeues); in event_queue_insert_active_later()
3411 TAILQ_INSERT_TAIL(&base->active_later_queue, evcb, evcb_active_next); in event_queue_insert_active_later()
3415 event_queue_insert_timeout(struct event_base *base, struct event *ev) in event_queue_insert_timeout() argument
3417 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_insert_timeout()
3425 INCR_EVENT_COUNT(base, ev->ev_flags); 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()
3434 min_heap_push_(&base->timeheap, ev); in event_queue_insert_timeout()
3439 event_queue_make_later_events_active(struct event_base *base) in event_queue_make_later_events_active() argument
3442 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_make_later_events_active()
3444 while ((evcb = TAILQ_FIRST(&base->active_later_queue))) { in event_queue_make_later_events_active()
3445 TAILQ_REMOVE(&base->active_later_queue, evcb, evcb_active_next); in event_queue_make_later_events_active()
3447 EVUTIL_ASSERT(evcb->evcb_pri < base->nactivequeues); in event_queue_make_later_events_active()
3448 TAILQ_INSERT_TAIL(&base->activequeues[evcb->evcb_pri], evcb, evcb_active_next); in event_queue_make_later_events_active()
3449 base->n_deferreds_queued += (evcb->evcb_closure == EV_CLOSURE_CB_SELF); in event_queue_make_later_events_active()
3587 struct event_base *base = arg; in evthread_notify_drain_eventfd() local
3593 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in evthread_notify_drain_eventfd()
3594 base->is_notify_pending = 0; in evthread_notify_drain_eventfd()
3595 EVBASE_RELEASE_LOCK(base, th_base_lock); in evthread_notify_drain_eventfd()
3603 struct event_base *base = arg; in evthread_notify_drain_default() local
3612 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in evthread_notify_drain_default()
3613 base->is_notify_pending = 0; in evthread_notify_drain_default()
3614 EVBASE_RELEASE_LOCK(base, th_base_lock); in evthread_notify_drain_default()
3618 evthread_make_base_notifiable(struct event_base *base) in evthread_make_base_notifiable() argument
3621 if (!base) in evthread_make_base_notifiable()
3624 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in evthread_make_base_notifiable()
3625 r = evthread_make_base_notifiable_nolock_(base); in evthread_make_base_notifiable()
3626 EVBASE_RELEASE_LOCK(base, th_base_lock); in evthread_make_base_notifiable()
3631 evthread_make_base_notifiable_nolock_(struct event_base *base) in evthread_make_base_notifiable_nolock_() argument
3636 if (base->th_notify_fn != NULL) { in evthread_make_base_notifiable_nolock_()
3637 /* The base is already notifiable: we're doing fine. */ in evthread_make_base_notifiable_nolock_()
3642 if (base->evsel == &kqops && event_kq_add_notify_event_(base) == 0) { in evthread_make_base_notifiable_nolock_()
3643 base->th_notify_fn = event_kq_notify_base_; in evthread_make_base_notifiable_nolock_()
3651 base->th_notify_fd[0] = evutil_eventfd_(0, in evthread_make_base_notifiable_nolock_()
3653 if (base->th_notify_fd[0] >= 0) { in evthread_make_base_notifiable_nolock_()
3654 base->th_notify_fd[1] = -1; in evthread_make_base_notifiable_nolock_()
3659 if (evutil_make_internal_pipe_(base->th_notify_fd) == 0) { in evthread_make_base_notifiable_nolock_()
3666 base->th_notify_fn = notify; in evthread_make_base_notifiable_nolock_()
3669 event_assign(&base->th_notify, base, base->th_notify_fd[0], in evthread_make_base_notifiable_nolock_()
3670 EV_READ|EV_PERSIST, cb, base); in evthread_make_base_notifiable_nolock_()
3673 base->th_notify.ev_flags |= EVLIST_INTERNAL; in evthread_make_base_notifiable_nolock_()
3674 event_priority_set(&base->th_notify, 0); in evthread_make_base_notifiable_nolock_()
3676 return event_add_nolock_(&base->th_notify, NULL, 0); in evthread_make_base_notifiable_nolock_()
3680 event_base_foreach_event_nolock_(struct event_base *base, in event_base_foreach_event_nolock_() argument
3688 if ((r = evmap_foreach_event_(base, fn, arg))) in event_base_foreach_event_nolock_()
3693 for (u = 0; u < base->timeheap.n; ++u) { in event_base_foreach_event_nolock_()
3694 ev = base->timeheap.p[u]; in event_base_foreach_event_nolock_()
3699 if ((r = fn(base, ev, arg))) in event_base_foreach_event_nolock_()
3705 for (i = 0; i < base->n_common_timeouts; ++i) { in event_base_foreach_event_nolock_()
3707 base->common_timeout_queues[i]; in event_base_foreach_event_nolock_()
3714 if ((r = fn(base, ev, arg))) in event_base_foreach_event_nolock_()
3721 for (i = 0; i < base->nactivequeues; ++i) { in event_base_foreach_event_nolock_()
3723 TAILQ_FOREACH(evcb, &base->activequeues[i], evcb_active_next) { in event_base_foreach_event_nolock_()
3731 if ((r = fn(base, ev, arg))) in event_base_foreach_event_nolock_()
3739 /* Helper for event_base_dump_events: called on each event in the event base;
3742 dump_inserted_event_fn(const struct event_base *base, const struct event *e, void *arg) in dump_inserted_event_fn() argument
3764 evutil_timeradd(&tv, &base->tv_clock_diff, &tv); in dump_inserted_event_fn()
3773 /* Helper for event_base_dump_events: called on each event in the event base;
3776 dump_active_event_fn(const struct event_base *base, const struct event *e, void *arg) in dump_active_event_fn() argument
3799 event_base_foreach_event(struct event_base *base, in event_base_foreach_event() argument
3803 if ((!fn) || (!base)) { in event_base_foreach_event()
3806 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_foreach_event()
3807 r = event_base_foreach_event_nolock_(base, fn, arg); in event_base_foreach_event()
3808 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_foreach_event()
3814 event_base_dump_events(struct event_base *base, FILE *output) in event_base_dump_events() argument
3816 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_dump_events()
3818 event_base_foreach_event_nolock_(base, dump_inserted_event_fn, output); in event_base_dump_events()
3821 event_base_foreach_event_nolock_(base, dump_active_event_fn, output); in event_base_dump_events()
3822 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_dump_events()
3826 event_base_active_by_fd(struct event_base *base, evutil_socket_t fd, short events) in event_base_active_by_fd() argument
3828 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_active_by_fd()
3832 evmap_io_active_(base, fd, events & (EV_READ|EV_WRITE|EV_CLOSED)); in event_base_active_by_fd()
3840 for (u = 0; u < base->timeheap.n; ++u) { in event_base_active_by_fd()
3841 ev = base->timeheap.p[u]; in event_base_active_by_fd()
3847 for (i = 0; i < base->n_common_timeouts; ++i) { in event_base_active_by_fd()
3848 struct common_timeout_list *ctl = base->common_timeout_queues[i]; in event_base_active_by_fd()
3858 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_active_by_fd()
3862 event_base_active_by_signal(struct event_base *base, int sig) in event_base_active_by_signal() argument
3864 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_active_by_signal()
3865 evmap_signal_active_(base, sig, 1); in event_base_active_by_signal()
3866 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_active_by_signal()
3871 event_base_add_virtual_(struct event_base *base) in event_base_add_virtual_() argument
3873 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_add_virtual_()
3874 base->virtual_event_count++; in event_base_add_virtual_()
3875 MAX_EVENT_COUNT(base->virtual_event_count_max, base->virtual_event_count); in event_base_add_virtual_()
3876 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_add_virtual_()
3880 event_base_del_virtual_(struct event_base *base) in event_base_del_virtual_() argument
3882 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_del_virtual_()
3883 EVUTIL_ASSERT(base->virtual_event_count > 0); in event_base_del_virtual_()
3884 base->virtual_event_count--; in event_base_del_virtual_()
3885 if (base->virtual_event_count == 0 && EVBASE_NEED_NOTIFY(base)) in event_base_del_virtual_()
3886 evthread_notify_base(base); in event_base_del_virtual_()
3887 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_del_virtual_()
3956 event_base_assert_ok_(struct event_base *base) in event_base_assert_ok_() argument
3958 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_assert_ok_()
3959 event_base_assert_ok_nolock_(base); in event_base_assert_ok_()
3960 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_assert_ok_()
3964 event_base_assert_ok_nolock_(struct event_base *base) in event_base_assert_ok_nolock_() argument
3970 evmap_check_integrity_(base); in event_base_assert_ok_nolock_()
3973 for (i = 1; i < (int)base->timeheap.n; ++i) { in event_base_assert_ok_nolock_()
3976 ev = base->timeheap.p[i]; in event_base_assert_ok_nolock_()
3977 p_ev = base->timeheap.p[parent]; in event_base_assert_ok_nolock_()
3984 for (i = 0; i < base->n_common_timeouts; ++i) { in event_base_assert_ok_nolock_()
3985 struct common_timeout_list *ctl = base->common_timeout_queues[i]; in event_base_assert_ok_nolock_()
3994 EVUTIL_ASSERT(is_common_timeout(&ev->ev_timeout,base)); in event_base_assert_ok_nolock_()
4002 for (i = 0; i < base->nactivequeues; ++i) { in event_base_assert_ok_nolock_()
4004 EVUTIL_ASSERT_TAILQ_OK(&base->activequeues[i], event_callback, evcb_active_next); in event_base_assert_ok_nolock_()
4005 TAILQ_FOREACH(evcb, &base->activequeues[i], evcb_active_next) { in event_base_assert_ok_nolock_()
4014 TAILQ_FOREACH(evcb, &base->active_later_queue, evcb_active_next) { in event_base_assert_ok_nolock_()
4019 EVUTIL_ASSERT(count == base->event_count_active); in event_base_assert_ok_nolock_()