mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-12 22:10:12 -04:00
Notify event base if there are no more events, so it can exit without delay
Fixes: #623 (cherry picked from commit 23c2914f6b430f2c2d74c267c13ffab3dda1b325)
This commit is contained in:
parent
44fa5b19f7
commit
d9d1c09e25
4
event.c
4
event.c
@ -2847,6 +2847,10 @@ event_del_nolock_(struct event *ev, int blocking)
|
|||||||
notify = 1;
|
notify = 1;
|
||||||
res = 0;
|
res = 0;
|
||||||
}
|
}
|
||||||
|
/* If we do not have events, let's notify event base so it can
|
||||||
|
* exit without waiting */
|
||||||
|
if (!event_haveevents(base) && !N_ACTIVE_CALLBACKS(base))
|
||||||
|
notify = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we are not in the right thread, we need to wake up the loop */
|
/* if we are not in the right thread, we need to wake up the loop */
|
||||||
|
@ -1039,6 +1039,34 @@ test_del_wait(void)
|
|||||||
end:
|
end:
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void null_cb(evutil_socket_t fd, short what, void *arg) {}
|
||||||
|
static void* test_del_notify_thread(void *arg)
|
||||||
|
{
|
||||||
|
event_dispatch();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
static void
|
||||||
|
test_del_notify(void)
|
||||||
|
{
|
||||||
|
struct event ev;
|
||||||
|
pthread_t thread;
|
||||||
|
|
||||||
|
test_ok = 1;
|
||||||
|
|
||||||
|
event_set(&ev, -1, EV_READ, null_cb, &ev);
|
||||||
|
event_add(&ev, NULL);
|
||||||
|
|
||||||
|
pthread_create(&thread, NULL, test_del_notify_thread, NULL);
|
||||||
|
|
||||||
|
{
|
||||||
|
struct timeval delay = { 0, 1000 };
|
||||||
|
evutil_usleep_(&delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
event_del(&ev);
|
||||||
|
pthread_join(thread, NULL);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -3452,6 +3480,7 @@ struct testcase_t main_testcases[] = {
|
|||||||
#ifdef EVENT__HAVE_PTHREADS
|
#ifdef EVENT__HAVE_PTHREADS
|
||||||
/** TODO: support win32 */
|
/** TODO: support win32 */
|
||||||
LEGACY(del_wait, TT_ISOLATED|TT_NEED_THREADS),
|
LEGACY(del_wait, TT_ISOLATED|TT_NEED_THREADS),
|
||||||
|
LEGACY(del_notify, TT_ISOLATED|TT_NEED_THREADS),
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
END_OF_TESTCASES
|
END_OF_TESTCASES
|
||||||
|
Loading…
x
Reference in New Issue
Block a user