Lines Matching refs:base

146 static int	evthread_notify_base(struct event_base *base);
325 #define EVENT_BASE_ASSERT_LOCKED(base) \ argument
326 EVLOCK_ASSERT_LOCKED((base)->th_base_lock)
357 gettime(struct event_base *base, struct timeval *tp) in gettime() argument
359 EVENT_BASE_ASSERT_LOCKED(base); in gettime()
361 if (base->tv_cache.tv_sec) { in gettime()
362 *tp = base->tv_cache; in gettime()
375 if (base->last_updated_clock_diff + CLOCK_SYNC_INTERVAL in gettime()
379 evutil_timersub(&tv, tp, &base->tv_clock_diff); in gettime()
380 base->last_updated_clock_diff = ts.tv_sec; in gettime()
391 event_base_gettimeofday_cached(struct event_base *base, struct timeval *tv) in event_base_gettimeofday_cached() argument
394 if (!base) { in event_base_gettimeofday_cached()
395 base = current_base; in event_base_gettimeofday_cached()
400 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_gettimeofday_cached()
401 if (base->tv_cache.tv_sec == 0) { in event_base_gettimeofday_cached()
405 evutil_timeradd(&base->tv_cache, &base->tv_clock_diff, tv); in event_base_gettimeofday_cached()
407 *tv = base->tv_cache; in event_base_gettimeofday_cached()
411 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_gettimeofday_cached()
417 clear_time_cache(struct event_base *base) in clear_time_cache() argument
419 base->tv_cache.tv_sec = 0; in clear_time_cache()
424 update_time_cache(struct event_base *base) in update_time_cache() argument
426 base->tv_cache.tv_sec = 0; in update_time_cache()
427 if (!(base->flags & EVENT_BASE_FLAG_NO_CACHE_TIME)) in update_time_cache()
428 gettime(base, &base->tv_cache); in update_time_cache()
434 struct event_base *base = event_base_new_with_config(NULL); in event_init() local
436 if (base == NULL) { in event_init()
441 current_base = base; in event_init()
443 return (base); in event_init()
449 struct event_base *base = NULL; in event_base_new() local
452 base = event_base_new_with_config(cfg); in event_base_new()
455 return base; in event_base_new()
491 event_base_get_features(const struct event_base *base) in event_base_get_features() argument
493 return base->evsel->features; in event_base_get_features()
507 struct event_base *base = baseptr; in notify_base_cbq_callback() local
508 if (EVBASE_NEED_NOTIFY(base)) in notify_base_cbq_callback()
509 evthread_notify_base(base); in notify_base_cbq_callback()
513 event_base_get_deferred_cb_queue(struct event_base *base) in event_base_get_deferred_cb_queue() argument
515 return base ? &base->defer_queue : NULL; in event_base_get_deferred_cb_queue()
555 struct event_base *base; in event_base_new_with_config() local
562 if ((base = mm_calloc(1, sizeof(struct event_base))) == NULL) { in event_base_new_with_config()
567 gettime(base, &base->event_tv); in event_base_new_with_config()
569 min_heap_ctor(&base->timeheap); in event_base_new_with_config()
570 TAILQ_INIT(&base->eventqueue); in event_base_new_with_config()
571 base->sig.ev_signal_pair[0] = -1; in event_base_new_with_config()
572 base->sig.ev_signal_pair[1] = -1; in event_base_new_with_config()
573 base->th_notify_fd[0] = -1; in event_base_new_with_config()
574 base->th_notify_fd[1] = -1; in event_base_new_with_config()
576 event_deferred_cb_queue_init(&base->defer_queue); in event_base_new_with_config()
577 base->defer_queue.notify_fn = notify_base_cbq_callback; in event_base_new_with_config()
578 base->defer_queue.notify_arg = base; in event_base_new_with_config()
580 base->flags = cfg->flags; in event_base_new_with_config()
582 evmap_io_initmap(&base->io); in event_base_new_with_config()
583 evmap_signal_initmap(&base->sigmap); in event_base_new_with_config()
584 event_changelist_init(&base->changelist); in event_base_new_with_config()
586 base->evbase = NULL; in event_base_new_with_config()
591 for (i = 0; eventops[i] && !base->evbase; i++) { in event_base_new_with_config()
607 base->evsel = eventops[i]; in event_base_new_with_config()
609 base->evbase = base->evsel->init(base); in event_base_new_with_config()
612 if (base->evbase == NULL) { in event_base_new_with_config()
615 base->evsel = NULL; in event_base_new_with_config()
616 event_base_free(base); in event_base_new_with_config()
621 event_msgx("libevent using: %s", base->evsel->name); in event_base_new_with_config()
624 if (event_base_priority_init(base, 1) < 0) { in event_base_new_with_config()
625 event_base_free(base); in event_base_new_with_config()
635 EVTHREAD_ALLOC_LOCK(base->th_base_lock, in event_base_new_with_config()
637 base->defer_queue.lock = base->th_base_lock; in event_base_new_with_config()
638 EVTHREAD_ALLOC_COND(base->current_event_cond); in event_base_new_with_config()
639 r = evthread_make_base_notifiable(base); in event_base_new_with_config()
642 event_base_free(base); in event_base_new_with_config()
650 event_base_start_iocp(base, cfg->n_cpus_hint); in event_base_new_with_config()
653 return (base); in event_base_new_with_config()
657 event_base_start_iocp(struct event_base *base, int n_cpus) in event_base_start_iocp() argument
660 if (base->iocp) in event_base_start_iocp()
662 base->iocp = event_iocp_port_launch(n_cpus); in event_base_start_iocp()
663 if (!base->iocp) { in event_base_start_iocp()
674 event_base_stop_iocp(struct event_base *base) in event_base_stop_iocp() argument
679 if (!base->iocp) in event_base_stop_iocp()
681 rv = event_iocp_shutdown(base->iocp, -1); in event_base_stop_iocp()
683 base->iocp = NULL; in event_base_stop_iocp()
688 event_base_free(struct event_base *base) in event_base_free() argument
697 if (base == NULL && current_base) in event_base_free()
698 base = current_base; in event_base_free()
700 if (base == current_base) in event_base_free()
703 if (base == NULL) { in event_base_free()
710 event_base_stop_iocp(base); in event_base_free()
714 if (base->th_notify_fd[0] != -1) { in event_base_free()
715 event_del(&base->th_notify); in event_base_free()
716 EVUTIL_CLOSESOCKET(base->th_notify_fd[0]); in event_base_free()
717 if (base->th_notify_fd[1] != -1) in event_base_free()
718 EVUTIL_CLOSESOCKET(base->th_notify_fd[1]); in event_base_free()
719 base->th_notify_fd[0] = -1; in event_base_free()
720 base->th_notify_fd[1] = -1; in event_base_free()
721 event_debug_unassign(&base->th_notify); in event_base_free()
725 for (ev = TAILQ_FIRST(&base->eventqueue); ev; ) { in event_base_free()
733 while ((ev = min_heap_top(&base->timeheap)) != NULL) { in event_base_free()
737 for (i = 0; i < base->n_common_timeouts; ++i) { in event_base_free()
739 base->common_timeout_queues[i]; in event_base_free()
753 if (base->common_timeout_queues) in event_base_free()
754 mm_free(base->common_timeout_queues); in event_base_free()
756 for (i = 0; i < base->nactivequeues; ++i) { in event_base_free()
757 for (ev = TAILQ_FIRST(&base->activequeues[i]); ev; ) { in event_base_free()
771 if (base->evsel != NULL && base->evsel->dealloc != NULL) in event_base_free()
772 base->evsel->dealloc(base); in event_base_free()
774 for (i = 0; i < base->nactivequeues; ++i) in event_base_free()
775 EVUTIL_ASSERT(TAILQ_EMPTY(&base->activequeues[i])); in event_base_free()
777 EVUTIL_ASSERT(min_heap_empty(&base->timeheap)); in event_base_free()
778 min_heap_dtor(&base->timeheap); in event_base_free()
780 mm_free(base->activequeues); in event_base_free()
782 EVUTIL_ASSERT(TAILQ_EMPTY(&base->eventqueue)); in event_base_free()
784 evmap_io_clear(&base->io); in event_base_free()
785 evmap_signal_clear(&base->sigmap); in event_base_free()
786 event_changelist_freemem(&base->changelist); in event_base_free()
788 EVTHREAD_FREE_LOCK(base->th_base_lock, EVTHREAD_LOCKTYPE_RECURSIVE); in event_base_free()
789 EVTHREAD_FREE_COND(base->current_event_cond); in event_base_free()
791 mm_free(base); in event_base_free()
796 event_reinit(struct event_base *base) in event_reinit() argument
803 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_reinit()
805 evsel = base->evsel; in event_reinit()
819 if (base->sig.ev_signal_added) { in event_reinit()
822 event_queue_remove(base, &base->sig.ev_signal, in event_reinit()
824 if (base->sig.ev_signal.ev_flags & EVLIST_ACTIVE) in event_reinit()
825 event_queue_remove(base, &base->sig.ev_signal, in event_reinit()
827 if (base->sig.ev_signal_pair[0] != -1) in event_reinit()
828 EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[0]); in event_reinit()
829 if (base->sig.ev_signal_pair[1] != -1) in event_reinit()
830 EVUTIL_CLOSESOCKET(base->sig.ev_signal_pair[1]); in event_reinit()
831 base->sig.ev_signal_added = 0; in event_reinit()
833 if (base->th_notify_fd[0] != -1) { in event_reinit()
837 event_queue_remove(base, &base->th_notify, in event_reinit()
839 if (base->th_notify.ev_flags & EVLIST_ACTIVE) in event_reinit()
840 event_queue_remove(base, &base->th_notify, in event_reinit()
842 base->sig.ev_signal_added = 0; in event_reinit()
843 EVUTIL_CLOSESOCKET(base->th_notify_fd[0]); in event_reinit()
844 if (base->th_notify_fd[1] != -1) in event_reinit()
845 EVUTIL_CLOSESOCKET(base->th_notify_fd[1]); in event_reinit()
846 base->th_notify_fd[0] = -1; in event_reinit()
847 base->th_notify_fd[1] = -1; in event_reinit()
848 event_debug_unassign(&base->th_notify); in event_reinit()
851 if (base->evsel->dealloc != NULL) in event_reinit()
852 base->evsel->dealloc(base); in event_reinit()
853 base->evbase = evsel->init(base); in event_reinit()
854 if (base->evbase == NULL) { in event_reinit()
861 event_changelist_freemem(&base->changelist); /* XXX */ in event_reinit()
862 evmap_io_clear(&base->io); in event_reinit()
863 evmap_signal_clear(&base->sigmap); in event_reinit()
865 TAILQ_FOREACH(ev, &base->eventqueue, ev_next) { in event_reinit()
867 if (ev == &base->sig.ev_signal) { in event_reinit()
874 if (evmap_io_add(base, ev->ev_fd, ev) == -1) in event_reinit()
877 if (evmap_signal_add(base, (int)ev->ev_fd, ev) == -1) in event_reinit()
883 res = evthread_make_base_notifiable(base); in event_reinit()
886 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_reinit()
1007 event_base_priority_init(struct event_base *base, int npriorities) in event_base_priority_init() argument
1011 if (N_ACTIVE_CALLBACKS(base) || npriorities < 1 in event_base_priority_init()
1015 if (npriorities == base->nactivequeues) in event_base_priority_init()
1018 if (base->nactivequeues) { in event_base_priority_init()
1019 mm_free(base->activequeues); in event_base_priority_init()
1020 base->nactivequeues = 0; in event_base_priority_init()
1024 base->activequeues = (struct event_list *) in event_base_priority_init()
1026 if (base->activequeues == NULL) { in event_base_priority_init()
1030 base->nactivequeues = npriorities; in event_base_priority_init()
1032 for (i = 0; i < base->nactivequeues; ++i) { in event_base_priority_init()
1033 TAILQ_INIT(&base->activequeues[i]); in event_base_priority_init()
1041 event_haveevents(struct event_base *base) in event_haveevents() argument
1044 return (base->virtual_event_count > 0 || base->event_count > 0); in event_haveevents()
1049 event_signal_closure(struct event_base *base, struct event *ev) in event_signal_closure() argument
1058 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_signal_closure()
1066 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_signal_closure()
1067 should_break = base->event_break; in event_signal_closure()
1068 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_signal_closure()
1104 const struct event_base *base) in is_common_timeout() argument
1110 return idx < base->n_common_timeouts; in is_common_timeout()
1125 get_common_timeout_list(struct event_base *base, const struct timeval *tv) in get_common_timeout_list() argument
1127 return base->common_timeout_queues[COMMON_TIMEOUT_IDX(tv)]; in get_common_timeout_list()
1133 struct event_base *base)
1136 &get_common_timeout_list(base, tv)->duration;
1161 struct event_base *base = ctl->base; in common_timeout_callback() local
1163 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in common_timeout_callback()
1164 gettime(base, &now); in common_timeout_callback()
1176 EVBASE_RELEASE_LOCK(base, th_base_lock); in common_timeout_callback()
1182 event_base_init_common_timeout(struct event_base *base, in event_base_init_common_timeout() argument
1190 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_init_common_timeout()
1193 if (is_common_timeout(duration, base)) in event_base_init_common_timeout()
1199 for (i = 0; i < base->n_common_timeouts; ++i) { in event_base_init_common_timeout()
1201 base->common_timeout_queues[i]; in event_base_init_common_timeout()
1205 EVUTIL_ASSERT(is_common_timeout(&ctl->duration, base)); in event_base_init_common_timeout()
1210 if (base->n_common_timeouts == MAX_COMMON_TIMEOUTS) { in event_base_init_common_timeout()
1216 if (base->n_common_timeouts_allocated == base->n_common_timeouts) { in event_base_init_common_timeout()
1217 int n = base->n_common_timeouts < 16 ? 16 : in event_base_init_common_timeout()
1218 base->n_common_timeouts*2; in event_base_init_common_timeout()
1220 mm_realloc(base->common_timeout_queues, in event_base_init_common_timeout()
1226 base->n_common_timeouts_allocated = n; in event_base_init_common_timeout()
1227 base->common_timeout_queues = newqueues; in event_base_init_common_timeout()
1238 (base->n_common_timeouts << COMMON_TIMEOUT_IDX_SHIFT); in event_base_init_common_timeout()
1239 evtimer_assign(&new_ctl->timeout_event, base, in event_base_init_common_timeout()
1243 new_ctl->base = base; in event_base_init_common_timeout()
1244 base->common_timeout_queues[base->n_common_timeouts++] = new_ctl; in event_base_init_common_timeout()
1249 EVUTIL_ASSERT(is_common_timeout(result, base)); in event_base_init_common_timeout()
1251 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_init_common_timeout()
1257 event_persist_closure(struct event_base *base, struct event *ev) in event_persist_closure() argument
1277 gettime(base, &now); in event_persist_closure()
1278 if (is_common_timeout(&ev->ev_timeout, base)) { in event_persist_closure()
1316 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_persist_closure()
1330 event_process_active_single_queue(struct event_base *base, in event_process_active_single_queue() argument
1340 event_queue_remove(base, ev, EVLIST_ACTIVE); in event_process_active_single_queue()
1354 base->current_event = ev; in event_process_active_single_queue()
1355 base->current_event_waiters = 0; in event_process_active_single_queue()
1360 event_signal_closure(base, ev); in event_process_active_single_queue()
1363 event_persist_closure(base, ev); in event_process_active_single_queue()
1367 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_process_active_single_queue()
1373 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_process_active_single_queue()
1375 base->current_event = NULL; in event_process_active_single_queue()
1376 if (base->current_event_waiters) { in event_process_active_single_queue()
1377 base->current_event_waiters = 0; in event_process_active_single_queue()
1378 EVTHREAD_COND_BROADCAST(base->current_event_cond); in event_process_active_single_queue()
1382 if (base->event_break) in event_process_active_single_queue()
1384 if (base->event_continue) in event_process_active_single_queue()
1428 event_process_active(struct event_base *base) in event_process_active() argument
1434 for (i = 0; i < base->nactivequeues; ++i) { in event_process_active()
1435 if (TAILQ_FIRST(&base->activequeues[i]) != NULL) { in event_process_active()
1436 base->event_running_priority = i; in event_process_active()
1437 activeq = &base->activequeues[i]; in event_process_active()
1438 c = event_process_active_single_queue(base, activeq); in event_process_active()
1440 base->event_running_priority = -1; in event_process_active()
1450 event_process_deferred_callbacks(&base->defer_queue,&base->event_break); in event_process_active()
1451 base->event_running_priority = -1; in event_process_active()
1472 event_base_get_method(const struct event_base *base) in event_base_get_method() argument
1474 EVUTIL_ASSERT(base); in event_base_get_method()
1475 return (base->evsel->name); in event_base_get_method()
1483 struct event_base *base = arg; in event_loopexit_cb() local
1484 base->event_gotterm = 1; in event_loopexit_cb()
1555 event_base_loop(struct event_base *base, int flags) in event_base_loop() argument
1557 const struct eventop *evsel = base->evsel; in event_base_loop()
1564 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_loop()
1566 if (base->running_loop) { in event_base_loop()
1569 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_loop()
1573 base->running_loop = 1; in event_base_loop()
1575 clear_time_cache(base); in event_base_loop()
1577 if (base->sig.ev_signal_added && base->sig.ev_n_signals_added) in event_base_loop()
1578 evsig_set_base(base); in event_base_loop()
1583 base->th_owner_id = EVTHREAD_GET_ID(); in event_base_loop()
1586 base->event_gotterm = base->event_break = 0; in event_base_loop()
1589 base->event_continue = 0; in event_base_loop()
1592 if (base->event_gotterm) { in event_base_loop()
1596 if (base->event_break) { in event_base_loop()
1600 timeout_correct(base, &tv); in event_base_loop()
1603 if (!N_ACTIVE_CALLBACKS(base) && !(flags & EVLOOP_NONBLOCK)) { in event_base_loop()
1604 timeout_next(base, &tv_p); in event_base_loop()
1614 if (!event_haveevents(base) && !N_ACTIVE_CALLBACKS(base)) { in event_base_loop()
1621 gettime(base, &base->event_tv); in event_base_loop()
1623 clear_time_cache(base); in event_base_loop()
1625 res = evsel->dispatch(base, tv_p); in event_base_loop()
1634 update_time_cache(base); in event_base_loop()
1636 timeout_process(base); in event_base_loop()
1638 if (N_ACTIVE_CALLBACKS(base)) { in event_base_loop()
1639 int n = event_process_active(base); in event_base_loop()
1641 && N_ACTIVE_CALLBACKS(base) == 0 in event_base_loop()
1650 clear_time_cache(base); in event_base_loop()
1651 base->running_loop = 0; in event_base_loop()
1653 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_loop()
1689 event_base_once(struct event_base *base, evutil_socket_t fd, short events, in event_base_once() argument
1714 evtimer_assign(&eonce->ev, base, event_once_cb, eonce); in event_base_once()
1718 event_assign(&eonce->ev, base, fd, events, event_once_cb, eonce); in event_base_once()
1736 event_assign(struct event *ev, struct event_base *base, evutil_socket_t fd, short events, void (*ca… in event_assign() argument
1738 if (!base) in event_assign()
1739 base = current_base; in event_assign()
1743 ev->ev_base = base; in event_assign()
1772 if (base != NULL) { in event_assign()
1774 ev->ev_pri = base->nactivequeues / 2; in event_assign()
1783 event_base_set(struct event_base *base, struct event *ev) in event_base_set() argument
1791 ev->ev_base = base; in event_base_set()
1792 ev->ev_pri = base->nactivequeues/2; in event_base_set()
1807 event_new(struct event_base *base, evutil_socket_t fd, short events, void (*cb)(evutil_socket_t, sh… in event_new() argument
1813 if (event_assign(ev, base, fd, events, cb, arg) < 0) { in event_new()
1996 evthread_notify_base_default(struct event_base *base) in evthread_notify_base_default() argument
2002 r = send(base->th_notify_fd[1], buf, 1, 0); in evthread_notify_base_default()
2004 r = write(base->th_notify_fd[1], buf, 1); in evthread_notify_base_default()
2013 evthread_notify_base_eventfd(struct event_base *base) in evthread_notify_base_eventfd() argument
2018 r = write(base->th_notify_fd[0], (void*) &msg, sizeof(msg)); in evthread_notify_base_eventfd()
2029 evthread_notify_base(struct event_base *base) in evthread_notify_base() argument
2031 EVENT_BASE_ASSERT_LOCKED(base); in evthread_notify_base()
2032 if (!base->th_notify_fn) in evthread_notify_base()
2034 if (base->is_notify_pending) in evthread_notify_base()
2036 base->is_notify_pending = 1; in evthread_notify_base()
2037 return base->th_notify_fn(base); in evthread_notify_base()
2048 struct event_base *base = ev->ev_base; in event_add_internal() local
2052 EVENT_BASE_ASSERT_LOCKED(base); in event_add_internal()
2071 if (min_heap_reserve(&base->timeheap, in event_add_internal()
2072 1 + min_heap_size(&base->timeheap)) == -1) in event_add_internal()
2081 if (base->current_event == ev && (ev->ev_events & EV_SIGNAL) in event_add_internal()
2082 && !EVBASE_IN_THREAD(base)) { in event_add_internal()
2083 ++base->current_event_waiters; in event_add_internal()
2084 EVTHREAD_COND_WAIT(base->current_event_cond, base->th_base_lock); in event_add_internal()
2091 res = evmap_io_add(base, ev->ev_fd, ev); in event_add_internal()
2093 res = evmap_signal_add(base, (int)ev->ev_fd, ev); in event_add_internal()
2095 event_queue_insert(base, ev, EVLIST_INSERTED); in event_add_internal()
2128 event_queue_remove(base, ev, EVLIST_TIMEOUT); in event_add_internal()
2146 event_queue_remove(base, ev, EVLIST_ACTIVE); in event_add_internal()
2149 gettime(base, &now); in event_add_internal()
2151 common_timeout = is_common_timeout(tv, base); in event_add_internal()
2168 event_queue_insert(base, ev, EVLIST_TIMEOUT); in event_add_internal()
2171 get_common_timeout_list(base, &ev->ev_timeout); in event_add_internal()
2186 if (res != -1 && notify && EVBASE_NEED_NOTIFY(base)) in event_add_internal()
2187 evthread_notify_base(base); in event_add_internal()
2217 struct event_base *base; in event_del_internal() local
2234 base = ev->ev_base; in event_del_internal()
2236 if (base->current_event == ev && !EVBASE_IN_THREAD(base)) { in event_del_internal()
2237 ++base->current_event_waiters; in event_del_internal()
2238 EVTHREAD_COND_WAIT(base->current_event_cond, base->th_base_lock); in event_del_internal()
2260 event_queue_remove(base, ev, EVLIST_TIMEOUT); in event_del_internal()
2264 event_queue_remove(base, ev, EVLIST_ACTIVE); in event_del_internal()
2267 event_queue_remove(base, ev, EVLIST_INSERTED); in event_del_internal()
2269 res = evmap_io_del(base, ev->ev_fd, ev); in event_del_internal()
2271 res = evmap_signal_del(base, (int)ev->ev_fd, ev); in event_del_internal()
2280 if (res != -1 && notify && EVBASE_NEED_NOTIFY(base)) in event_del_internal()
2281 evthread_notify_base(base); in event_del_internal()
2309 struct event_base *base; in event_active_nolock() local
2321 base = ev->ev_base; in event_active_nolock()
2323 EVENT_BASE_ASSERT_LOCKED(base); in event_active_nolock()
2327 if (ev->ev_pri < base->event_running_priority) in event_active_nolock()
2328 base->event_continue = 1; in event_active_nolock()
2332 if (base->current_event == ev && !EVBASE_IN_THREAD(base)) { in event_active_nolock()
2333 ++base->current_event_waiters; in event_active_nolock()
2334 EVTHREAD_COND_WAIT(base->current_event_cond, base->th_base_lock); in event_active_nolock()
2341 event_queue_insert(base, ev, EVLIST_ACTIVE); in event_active_nolock()
2343 if (EVBASE_NEED_NOTIFY(base)) in event_active_nolock()
2344 evthread_notify_base(base); in event_active_nolock()
2398 timeout_next(struct event_base *base, struct timeval **tv_p) in timeout_next() argument
2406 ev = min_heap_top(&base->timeheap); in timeout_next()
2414 if (gettime(base, &now) == -1) { in timeout_next()
2441 timeout_correct(struct event_base *base, struct timeval *tv) in timeout_correct() argument
2453 gettime(base, tv); in timeout_correct()
2455 if (evutil_timercmp(tv, &base->event_tv, >=)) { in timeout_correct()
2456 base->event_tv = *tv; in timeout_correct()
2462 evutil_timersub(&base->event_tv, tv, &off); in timeout_correct()
2468 pev = base->timeheap.p; in timeout_correct()
2469 size = base->timeheap.n; in timeout_correct()
2474 for (i=0; i<base->n_common_timeouts; ++i) { in timeout_correct()
2477 base->common_timeout_queues[i]; in timeout_correct()
2489 base->event_tv = *tv; in timeout_correct()
2494 timeout_process(struct event_base *base) in timeout_process() argument
2500 if (min_heap_empty(&base->timeheap)) { in timeout_process()
2504 gettime(base, &now); in timeout_process()
2506 while ((ev = min_heap_top(&base->timeheap))) { in timeout_process()
2521 event_queue_remove(struct event_base *base, struct event *ev, int queue) in event_queue_remove() argument
2523 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_remove()
2532 base->event_count--; in event_queue_remove()
2537 TAILQ_REMOVE(&base->eventqueue, ev, ev_next); in event_queue_remove()
2540 base->event_count_active--; in event_queue_remove()
2541 TAILQ_REMOVE(&base->activequeues[ev->ev_pri], in event_queue_remove()
2545 if (is_common_timeout(&ev->ev_timeout, base)) { in event_queue_remove()
2547 get_common_timeout_list(base, &ev->ev_timeout); in event_queue_remove()
2551 min_heap_erase(&base->timeheap, ev); in event_queue_remove()
2591 event_queue_insert(struct event_base *base, struct event *ev, int queue) in event_queue_insert() argument
2593 EVENT_BASE_ASSERT_LOCKED(base); in event_queue_insert()
2606 base->event_count++; in event_queue_insert()
2611 TAILQ_INSERT_TAIL(&base->eventqueue, ev, ev_next); in event_queue_insert()
2614 base->event_count_active++; in event_queue_insert()
2615 TAILQ_INSERT_TAIL(&base->activequeues[ev->ev_pri], in event_queue_insert()
2619 if (is_common_timeout(&ev->ev_timeout, base)) { in event_queue_insert()
2621 get_common_timeout_list(base, &ev->ev_timeout); in event_queue_insert()
2624 min_heap_push(&base->timeheap, ev); in event_queue_insert()
2736 struct event_base *base = arg; in evthread_notify_drain_eventfd() local
2742 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in evthread_notify_drain_eventfd()
2743 base->is_notify_pending = 0; in evthread_notify_drain_eventfd()
2744 EVBASE_RELEASE_LOCK(base, th_base_lock); in evthread_notify_drain_eventfd()
2752 struct event_base *base = arg; in evthread_notify_drain_default() local
2761 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in evthread_notify_drain_default()
2762 base->is_notify_pending = 0; in evthread_notify_drain_default()
2763 EVBASE_RELEASE_LOCK(base, th_base_lock); in evthread_notify_drain_default()
2767 evthread_make_base_notifiable(struct event_base *base) in evthread_make_base_notifiable() argument
2773 if (!base) in evthread_make_base_notifiable()
2776 if (base->th_notify_fd[0] >= 0) in evthread_make_base_notifiable()
2783 base->th_notify_fd[0] = eventfd(0, EFD_CLOEXEC); in evthread_make_base_notifiable()
2784 if (base->th_notify_fd[0] >= 0) { in evthread_make_base_notifiable()
2785 evutil_make_socket_closeonexec(base->th_notify_fd[0]); in evthread_make_base_notifiable()
2791 if (base->th_notify_fd[0] < 0) { in evthread_make_base_notifiable()
2792 if ((base->evsel->features & EV_FEATURE_FDS)) { in evthread_make_base_notifiable()
2793 if (pipe(base->th_notify_fd) < 0) { in evthread_make_base_notifiable()
2796 evutil_make_socket_closeonexec(base->th_notify_fd[0]); in evthread_make_base_notifiable()
2797 evutil_make_socket_closeonexec(base->th_notify_fd[1]); in evthread_make_base_notifiable()
2808 if (base->th_notify_fd[0] < 0) { in evthread_make_base_notifiable()
2810 base->th_notify_fd) == -1) { in evthread_make_base_notifiable()
2814 evutil_make_socket_closeonexec(base->th_notify_fd[0]); in evthread_make_base_notifiable()
2815 evutil_make_socket_closeonexec(base->th_notify_fd[1]); in evthread_make_base_notifiable()
2819 evutil_make_socket_nonblocking(base->th_notify_fd[0]); in evthread_make_base_notifiable()
2821 base->th_notify_fn = notify; in evthread_make_base_notifiable()
2831 if (base->th_notify_fd[1] > 0) in evthread_make_base_notifiable()
2832 evutil_make_socket_nonblocking(base->th_notify_fd[1]); in evthread_make_base_notifiable()
2835 event_assign(&base->th_notify, base, base->th_notify_fd[0], in evthread_make_base_notifiable()
2836 EV_READ|EV_PERSIST, cb, base); in evthread_make_base_notifiable()
2839 base->th_notify.ev_flags |= EVLIST_INTERNAL; in evthread_make_base_notifiable()
2840 event_priority_set(&base->th_notify, 0); in evthread_make_base_notifiable()
2842 return event_add(&base->th_notify, NULL); in evthread_make_base_notifiable()
2846 event_base_dump_events(struct event_base *base, FILE *output) in event_base_dump_events() argument
2851 TAILQ_FOREACH(e, &base->eventqueue, ev_next) { in event_base_dump_events()
2861 for (i = 0; i < base->nactivequeues; ++i) { in event_base_dump_events()
2862 if (TAILQ_EMPTY(&base->activequeues[i])) in event_base_dump_events()
2865 TAILQ_FOREACH(e, &base->eventqueue, ev_next) { in event_base_dump_events()
2877 event_base_add_virtual(struct event_base *base) in event_base_add_virtual() argument
2879 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_add_virtual()
2880 base->virtual_event_count++; in event_base_add_virtual()
2881 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_add_virtual()
2885 event_base_del_virtual(struct event_base *base) in event_base_del_virtual() argument
2887 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_del_virtual()
2888 EVUTIL_ASSERT(base->virtual_event_count > 0); in event_base_del_virtual()
2889 base->virtual_event_count--; in event_base_del_virtual()
2890 if (base->virtual_event_count == 0 && EVBASE_NEED_NOTIFY(base)) in event_base_del_virtual()
2891 evthread_notify_base(base); in event_base_del_virtual()
2892 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_del_virtual()
2911 event_base_assert_ok(struct event_base *base) in event_base_assert_ok() argument
2914 EVBASE_ACQUIRE_LOCK(base, th_base_lock); in event_base_assert_ok()
2915 evmap_check_integrity(base); in event_base_assert_ok()
2918 for (i = 1; i < (int)base->timeheap.n; ++i) { in event_base_assert_ok()
2921 ev = base->timeheap.p[i]; in event_base_assert_ok()
2922 p_ev = base->timeheap.p[parent]; in event_base_assert_ok()
2929 for (i = 0; i < base->n_common_timeouts; ++i) { in event_base_assert_ok()
2930 struct common_timeout_list *ctl = base->common_timeout_queues[i]; in event_base_assert_ok()
2936 EVUTIL_ASSERT(is_common_timeout(&ev->ev_timeout,base)); in event_base_assert_ok()
2942 EVBASE_RELEASE_LOCK(base, th_base_lock); in event_base_assert_ok()