Mercurial > urweb
comparison 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 |
comparison
equal
deleted
inserted
replaced
1671:a54d223c3a7f | 1672:ea131de361d9 |
---|---|
157 // Persistent client state | 157 // Persistent client state |
158 | 158 |
159 static client **clients, *clients_free, *clients_used; | 159 static client **clients, *clients_free, *clients_used; |
160 static unsigned n_clients; | 160 static unsigned n_clients; |
161 | 161 |
162 static pthread_mutex_t clients_mutex = PTHREAD_MUTEX_INITIALIZER; | 162 static pthread_mutex_t clients_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; |
163 | 163 |
164 size_t uw_messages_max = SIZE_MAX; | 164 size_t uw_messages_max = SIZE_MAX; |
165 size_t uw_clients_max = SIZE_MAX; | 165 size_t uw_clients_max = SIZE_MAX; |
166 | 166 |
167 void *uw_init_client_data(); | 167 void *uw_init_client_data(); |
175 | 175 |
176 if (clients_free) { | 176 if (clients_free) { |
177 c = clients_free; | 177 c = clients_free; |
178 clients_free = clients_free->next; | 178 clients_free = clients_free->next; |
179 } | 179 } |
180 else if (n_clients >= uw_clients_max) | 180 else if (n_clients >= uw_clients_max) { |
181 pthread_mutex_unlock(&clients_mutex); | |
181 return NULL; | 182 return NULL; |
182 else { | 183 } else { |
183 ++n_clients; | 184 ++n_clients; |
184 clients = realloc(clients, sizeof(client) * n_clients); | 185 clients = realloc(clients, sizeof(client) * n_clients); |
185 c = malloc(sizeof(client)); | 186 c = malloc(sizeof(client)); |
186 c->id = n_clients-1; | 187 c->id = n_clients-1; |
187 pthread_mutex_init(&c->lock, NULL); | 188 pthread_mutex_init(&c->lock, NULL); |