kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit fecbd058cb0ca1e3a7e5c6bdce5c935fc177bef1
parent e428886e16c18671b94f25840915f65532c341d8
Author: Joris Vink <joris@coders.se>
Date:   Fri, 31 May 2013 14:24:00 +0200

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

Diffstat:
src/kore.c | 28+++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/src/kore.c b/src/kore.c @@ -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--; } }