commit ac025adaa75c6ea1c0d1b17df60ba6fb8d014c0e
parent e10486fa108df2eb954df81ffcbf5f82d2539c14
Author: Joris Vink <joris@coders.se>
Date: Thu, 24 Oct 2013 09:05:46 +0200
Make kore_worker_acceptlock_release() available to loaded modules.
This allows us to move the accept lock manually to another Kore worker
in case we own it and are about to do some heavy lifting on the current
Kore worker.
Diffstat:
4 files changed, 29 insertions(+), 22 deletions(-)
diff --git a/includes/kore.h b/includes/kore.h
@@ -260,6 +260,7 @@ void kore_worker_wait(int);
void kore_worker_init(void);
void kore_worker_shutdown(void);
void kore_worker_dispatch_signal(int);
+void kore_worker_acceptlock_release(void);
void kore_worker_spawn(u_int16_t, u_int16_t);
void kore_worker_entry(struct kore_worker *);
void kore_worker_connection_add(struct connection *);
diff --git a/modules/example/module.conf b/modules/example/module.conf
@@ -97,6 +97,7 @@ domain localhost {
static /b64test serve_b64test
static /spdy-reset serve_spdyreset
static /upload serve_file_upload
+ static /lock-test serve_lock_test
}
#domain domain.com {
diff --git a/modules/example/src/example.c b/modules/example/src/example.c
@@ -25,6 +25,7 @@ int serve_intro(struct http_request *);
int serve_b64test(struct http_request *);
int serve_spdyreset(struct http_request *);
int serve_file_upload(struct http_request *);
+int serve_lock_test(struct http_request *);
void my_callback(void);
void test_base64(u_int8_t *, u_int32_t, struct kore_buf *);
@@ -165,6 +166,15 @@ serve_file_upload(struct http_request *req)
return (r);
}
+int
+serve_lock_test(struct http_request *req)
+{
+ kore_log(LOG_NOTICE, "lock-test called on worker %d", worker->id);
+ kore_worker_acceptlock_release();
+
+ return (http_response(req, 200, (u_int8_t *)"OK", 2));
+}
+
void
test_base64(u_int8_t *src, u_int32_t slen, struct kore_buf *res)
{
diff --git a/src/worker.c b/src/worker.c
@@ -48,7 +48,6 @@ static int worker_unlock(void);
static void worker_decide_next(void);
static void kore_worker_acceptlock_obtain(void);
-static void kore_worker_acceptlock_release(void);
static TAILQ_HEAD(, connection) disconnected;
static TAILQ_HEAD(, connection) worker_clients;
@@ -236,10 +235,8 @@ kore_worker_entry(struct kore_worker *kw)
if (((worker->accepted >= worker->accept_treshold) ||
(worker_active_connections >= worker_max_connections)) &&
- worker->has_lock) {
- worker->accepted = 0;
+ worker->has_lock)
kore_worker_acceptlock_release();
- }
http_process();
@@ -381,6 +378,22 @@ kore_worker_wait(int final)
}
}
+void
+kore_worker_acceptlock_release(void)
+{
+ if (worker_count == 1)
+ return;
+
+ if (worker->has_lock != 1)
+ return;
+
+ if (worker_unlock()) {
+ worker->accepted = 0;
+ worker->has_lock = 0;
+ kore_platform_disable_accept();
+ }
+}
+
static void
kore_worker_acceptlock_obtain(void)
{
@@ -396,24 +409,6 @@ kore_worker_acceptlock_obtain(void)
}
}
-static void
-kore_worker_acceptlock_release(void)
-{
- if (worker_count == 1)
- return;
-
- if (worker->has_lock != 1) {
- kore_log(LOG_NOTICE,
- "kore_worker_acceptlock_release() != 1");
- return;
- }
-
- if (worker_unlock()) {
- worker->has_lock = 0;
- kore_platform_disable_accept();
- }
-}
-
static int
worker_trylock(void)
{