changeset 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 dae2c6fbf16c
files src/c/cgi.c src/c/fastcgi.c src/c/http.c src/c/urweb.c
diffstat 4 files changed, 7 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/c/cgi.c	Tue Jan 10 15:34:18 2012 -0500
+++ b/src/c/cgi.c	Tue Jan 10 17:32:48 2012 -0500
@@ -131,8 +131,7 @@
   if (uw_get_app(ctx)->db_begin(ctx))
     uw_error(ctx, FATAL, "Error running SQL BEGIN");
   uw_get_app(ctx)->expunger(ctx, cli);
-  if (uw_get_app(ctx)->db_commit(ctx))
-    uw_error(ctx, FATAL, "Error running SQL COMMIT");
+  uw_commit(ctx);
 }
 
 void uw_post_expunge(uw_context ctx, void *data) {
--- a/src/c/fastcgi.c	Tue Jan 10 15:34:18 2012 -0500
+++ b/src/c/fastcgi.c	Tue Jan 10 17:32:48 2012 -0500
@@ -632,8 +632,7 @@
   if (uw_get_app(ctx)->db_begin(ctx))
     uw_error(ctx, FATAL, "Error running SQL BEGIN");
   uw_get_app(ctx)->expunger(ctx, cli);
-  if (uw_get_app(ctx)->db_commit(ctx))
-    uw_error(ctx, FATAL, "Error running SQL COMMIT");
+  uw_commit(ctx);
 }
 
 void uw_post_expunge(uw_context ctx, void *data) {
--- a/src/c/http.c	Tue Jan 10 15:34:18 2012 -0500
+++ b/src/c/http.c	Tue Jan 10 17:32:48 2012 -0500
@@ -354,8 +354,7 @@
   if (uw_get_app(ctx)->db_begin(ctx))
     uw_error(ctx, FATAL, "Error running SQL BEGIN");
   uw_get_app(ctx)->expunger(ctx, cli);
-  if (uw_get_app(ctx)->db_commit(ctx))
-    uw_error(ctx, FATAL, "Error running SQL COMMIT");
+  uw_commit(ctx);
 }
 
 void uw_post_expunge(uw_context ctx, void *data) {
--- 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));