diff options
author | Adam Chlipala <adamc@hcoop.net> | 2009-04-02 13:48:59 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2009-04-02 13:48:59 -0400 |
commit | 1afc9f4ed063a822883c5c752b045b3fe8fc8693 (patch) | |
tree | 7af63574c59ba2ed7af869da994d8d4d27e1853a | |
parent | c304fcda63a1c797c375da3817cefd127055b35b (diff) |
Make sure only one pull request runs at a time for each client
-rw-r--r-- | src/c/urweb.c | 6 |
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"; |