aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-04-02 13:48:59 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-04-02 13:48:59 -0400
commitfc19366c97d980fc47e23fc9404d5c661da46fd0 (patch)
tree7af63574c59ba2ed7af869da994d8d4d27e1853a /src
parent0239a9fe128d261f7abeaedc61414d68db985358 (diff)
Make sure only one pull request runs at a time for each client
Diffstat (limited to 'src')
-rw-r--r--src/c/urweb.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 1165c5d1..ed19305e 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -94,7 +94,7 @@ typedef struct client {
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 @@ static client *new_client() {
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 @@ static void use_client(client *c) {
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";