Skip to content

Commit

Permalink
Unlock on early returns in zkrb_enqueue and zkrb_queue_free
Browse files Browse the repository at this point in the history
May not need the dead variable with these in place.
  • Loading branch information
jmhodges committed Jan 31, 2011
1 parent d88441c commit e3fed3d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ext/zookeeper_lib.c
Expand Up @@ -27,6 +27,7 @@ pthread_mutex_t zkrb_q_mutex = PTHREAD_MUTEX_INITIALIZER;
void zkrb_enqueue(zkrb_queue_t *q, zkrb_event_t *elt) {
pthread_mutex_lock(&zkrb_q_mutex);
if (q == NULL || q->tail == NULL || q->dead) {
pthread_mutex_unlock(&zkrb_q_mutex);
return;
}
q->tail->event = elt;
Expand Down Expand Up @@ -75,10 +76,14 @@ zkrb_queue_t *zkrb_queue_alloc(void) {

void zkrb_queue_free(zkrb_queue_t *queue) {
pthread_mutex_lock(&zkrb_q_mutex);
if (queue == NULL || queue->dead) return;
if (queue == NULL || queue->dead) {
pthread_mutex_unlock(&zkrb_q_mutex);
return;
}

queue->dead = 1;
pthread_mutex_unlock(&zkrb_q_mutex);
zkrb_event_t *elt = NULL;
pthread_mutex_unlock(&zkrb_q_mutex);

while ((elt = zkrb_dequeue(queue)) != NULL) {
zkrb_event_free(elt);
Expand Down

0 comments on commit e3fed3d

Please sign in to comment.