rework the worker thread so there's actually time to schedule more then one request at a time on them.

This commit is contained in:
Joris Vink 2013-05-31 14:24:00 +02:00
parent e428886e16
commit fecbd058cb
1 changed files with 15 additions and 13 deletions

View File

@ -542,32 +542,35 @@ kore_worker_init(void)
static void *
kore_worker_entry(void *arg)
{
u_int8_t retry;
struct http_request *req, *next;
struct http_request *req;
struct kore_worker *kw = (struct kore_worker *)arg;
int r, (*hdlr)(struct http_request *);
pthread_mutex_lock(&(kw->lock));
for (;;) {
if (retry == 0)
pthread_cond_wait(&(kw->cond), &(kw->lock));
pthread_cond_wait(&(kw->cond), &(kw->lock));
while (!TAILQ_EMPTY(&(kw->requests))) {
req = TAILQ_FIRST(&(kw->requests));
TAILQ_REMOVE(&(kw->requests), req, list);
pthread_mutex_unlock(&(kw->lock));
retry = 0;
for (req = TAILQ_FIRST(&(kw->requests)); req != NULL;
req = next) {
next = TAILQ_NEXT(req, list);
if (req->flags & HTTP_REQUEST_DELETE) {
pthread_mutex_lock(&(kw->lock));
kw->load--;
TAILQ_REMOVE(&(kw->requests), req, list);
http_request_free(req);
continue;
}
if (!(req->flags & HTTP_REQUEST_COMPLETE))
if (!(req->flags & HTTP_REQUEST_COMPLETE)) {
pthread_mutex_lock(&(kw->lock));
TAILQ_INSERT_TAIL(&(kw->requests), req, list);
continue;
}
if (pthread_mutex_trylock(&(req->owner->lock))) {
retry = 1;
pthread_mutex_lock(&(kw->lock));
TAILQ_INSERT_TAIL(&(kw->requests), req, list);
continue;
}
@ -587,9 +590,8 @@ kore_worker_entry(void *arg)
pthread_mutex_unlock(&(req->owner->lock));
TAILQ_REMOVE(&(kw->requests), req, list);
pthread_mutex_lock(&(kw->lock));
http_request_free(req);
kw->load--;
}
}