diff options
author | 2012-01-10 17:32:48 -0500 | |
---|---|---|
committer | 2012-01-10 17:32:48 -0500 | |
commit | 8c3377398239860b510401a600b475eebca615d6 (patch) | |
tree | 746dd20a8a93faa9baefd4ee3a5feaebb9f9fac9 /src/c/urweb.c | |
parent | 8107368cf21db442473f7dcde20240688c6f156b (diff) |
Fix some locking issues for client array
Diffstat (limited to 'src/c/urweb.c')
-rw-r--r-- | src/c/urweb.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c index 1a193c53..915a8c76 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -159,7 +159,7 @@ typedef struct client { 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 @@ static client *new_client() { 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)); |