diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-10-21 03:54:00 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-10-21 03:54:00 +0000 |
commit | 6b22e74aa187f2bbabb58652070af27fff6f547e (patch) | |
tree | 412937b5b067186fb0c665a7e6a1a39a26ad4fe1 /epoll.c | |
parent | 50825466821c87f55a7549df47086f7412a5a726 (diff) | |
download | libevent-6b22e74aa187f2bbabb58652070af27fff6f547e.tar.gz |
Add locking to event_base_loop.
This is harder than it sounds, since we need to make sure to
release the lock around the key call to the kernel (e.g.,
select, epoll_wait, kevent), AND we need to make sure that
none of the fields that are used in that call are touched by
anything that might be running concurrently in another
thread. I managed to do this pretty well for everything but
poll(). With poll, I needed to introduce a copy of the
event_set structure.
This patch also fixes a bug in win32.c where we called
realloc() instead of mm_realloc().
svn:r1450
Diffstat (limited to 'epoll.c')
-rw-r--r-- | epoll.c | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -51,6 +51,8 @@ #include "event-internal.h" #include "evsignal-internal.h" +#include "event2/thread.h" +#include "evthread-internal.h" #include "log-internal.h" #include "evmap-internal.h" @@ -148,8 +150,12 @@ epoll_dispatch(struct event_base *base, struct timeval *tv) timeout = MAX_EPOLL_TIMEOUT_MSEC; } + EVBASE_RELEASE_LOCK(base, EVTHREAD_WRITE, th_base_lock); + res = epoll_wait(epollop->epfd, events, epollop->nevents, timeout); + EVBASE_ACQUIRE_LOCK(base, EVTHREAD_WRITE, th_base_lock); + if (res == -1) { if (errno != EINTR) { event_warn("epoll_wait"); |