From 5ebf2e4cd8ea3184b620e162ed787b50b950eee0 Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Fri, 29 Apr 2016 10:55:20 +0800 Subject: [PATCH] unlock event queue when handling event. and make lock scope smaller. --- src/pc_pomelo.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pc_pomelo.c b/src/pc_pomelo.c index 51f1fc9..899c653 100644 --- a/src/pc_pomelo.c +++ b/src/pc_pomelo.c @@ -350,8 +350,6 @@ int pc_client_poll(pc_client_t* client) return PC_RC_ERROR; } - pc_mutex_lock(&client->event_mutex); - /* * `is_in_poll` is used to avoid recursive invocation of pc_client_poll * by identical thread as `pc_mutex_t` is recursive. @@ -362,21 +360,25 @@ int pc_client_poll(pc_client_t* client) if (!client->is_in_poll) { client->is_in_poll = 1; + pc_mutex_lock(&client->event_mutex); while(!QUEUE_EMPTY(&client->pending_ev_queue)) { q = QUEUE_HEAD(&client->pending_ev_queue); ev = (pc_event_t*) QUEUE_DATA(q, pc_event_t, queue); QUEUE_REMOVE(&ev->queue); + pc_mutex_unlock(&client->event_mutex); + QUEUE_INIT(&ev->queue); assert((PC_IS_PRE_ALLOC(ev->type) && PC_PRE_ALLOC_IS_BUSY(ev->type)) || PC_IS_DYN_ALLOC(ev->type)); pc__handle_event(client, ev); + pc_mutex_lock(&client->event_mutex); } + pc_mutex_unlock(&client->event_mutex); client->is_in_poll = 0; } - pc_mutex_unlock(&client->event_mutex); return PC_RC_OK; }