From 6b22e74aa187f2bbabb58652070af27fff6f547e Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 21 Oct 2009 03:54:00 +0000 Subject: 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 --- evport.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'evport.c') 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); -- cgit v1.2.1