changeset 689:b6a8425e1b1f

Make sure only one pull request runs at a time for each client
author Adam Chlipala <adamc@hcoop.net>
date Thu, 02 Apr 2009 13:48:59 -0400 (2009-04-02)
parents 829887ca47a6
children 01b6f2ee2ef0
files src/c/urweb.c
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/c/urweb.c	Thu Apr 02 13:31:13 2009 -0400
+++ b/src/c/urweb.c	Thu Apr 02 13:48:59 2009 -0400
@@ -94,7 +94,7 @@
   usage mode;
   int pass;
   struct client *next;
-  pthread_mutex_t lock;
+  pthread_mutex_t lock, pull_lock;
   buf msgs;
   int sock;
   time_t last_contact;
@@ -125,6 +125,7 @@
     c = malloc(sizeof(client));
     c->id = n_clients-1;
     pthread_mutex_init(&c->lock, NULL);
+    pthread_mutex_init(&c->pull_lock, NULL);
     buf_init(&c->msgs, 0);
     clients[n_clients-1] = c;
   }
@@ -151,12 +152,15 @@
   pthread_mutex_lock(&c->lock);
   ++c->refcount;
   pthread_mutex_unlock(&c->lock);
+  pthread_mutex_lock(&c->pull_lock);
 }
 
 static void release_client(client *c) {
+  pthread_mutex_unlock(&c->pull_lock);
   pthread_mutex_lock(&c->lock);
   --c->refcount;
   pthread_mutex_unlock(&c->lock);
+
 }
 
 static const char begin_msgs[] = "HTTP/1.1 200 OK\r\nContent-type: text/plain\r\n\r\n";