diff src/c/urweb.c @ 1672:ea131de361d9

Fix some locking issues for client array
author Adam Chlipala <adam@chlipala.net>
date Tue, 10 Jan 2012 17:32:48 -0500
parents a54d223c3a7f
children 3636d0eeb39c
line wrap: on
line diff
--- a/src/c/urweb.c	Tue Jan 10 15:34:18 2012 -0500
+++ b/src/c/urweb.c	Tue Jan 10 17:32:48 2012 -0500
@@ -159,7 +159,7 @@
 static client **clients, *clients_free, *clients_used;
 static unsigned n_clients;
 
-static pthread_mutex_t clients_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t clients_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
 
 size_t uw_messages_max = SIZE_MAX;
 size_t uw_clients_max = SIZE_MAX;
@@ -177,9 +177,10 @@
     c = clients_free;
     clients_free = clients_free->next;
   }
-  else if (n_clients >= uw_clients_max)
+  else if (n_clients >= uw_clients_max) {
+    pthread_mutex_unlock(&clients_mutex);
     return NULL;
-  else {
+  } else {
     ++n_clients;
     clients = realloc(clients, sizeof(client) * n_clients);
     c = malloc(sizeof(client));