summaryrefslogtreecommitdiff
path: root/evport.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2009-10-21 03:54:00 +0000
committerNick Mathewson <nickm@torproject.org>2009-10-21 03:54:00 +0000
commit6b22e74aa187f2bbabb58652070af27fff6f547e (patch)
tree412937b5b067186fb0c665a7e6a1a39a26ad4fe1 /evport.c
parent50825466821c87f55a7549df47086f7412a5a726 (diff)
downloadlibevent-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 'evport.c')
-rw-r--r--evport.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/evport.c b/evport.c
index 55bbe800..32e373c0 100644
--- a/evport.c
+++ b/evport.c
@@ -303,8 +303,14 @@ evport_dispatch(struct event_base *base, struct timeval *tv)
}
}
- if ((res = port_getn(epdp->ed_port, pevtlist, EVENTS_PER_GETN,
- (unsigned int *) &nevents, ts_p)) == -1) {
+ EVBASE_RELEASE_LOCK(base, EVTHREAD_WRITE, th_base_lock);
+
+ res = port_getn(epdp->ed_port, pevtlist, EVENTS_PER_GETN,
+ (unsigned int *) &nevents, ts_p);
+
+ EVBASE_ACQUIRE_LOCK(base, EVTHREAD_WRITE, th_base_lock);
+
+ if (res == -1) {
if (errno == EINTR || errno == EAGAIN) {
evsig_process(base);
return (0);