Skip to content

Commit

Permalink
unlock event queue when handling event.
Browse files Browse the repository at this point in the history
and make lock scope smaller.
  • Loading branch information
xpol committed Apr 29, 2016
1 parent 4e3d587 commit 5ebf2e4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/pc_pomelo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand Down

0 comments on commit 5ebf2e4

Please sign in to comment.