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 02e7359970137605f5df650c294472a2e50e5e7b
parent 52d14a3fbf64cf0703fc461e9c5d02ccc5344d8a
Author: Joris Vink <joris@coders.se>
Date:   Wed, 11 Jul 2018 18:00:16 +0200

Add kore_worker_make_busy().

Calling this from your page handler will cause your current worker
to give up the acceptlock (if it holds it).

This is particularly useful if you are about to run code that may block
a bit longer then you are comfortable with. Calling this will cause
the acceptlock to shuffle to another free worker which in turn makes
sure your application can keep accepting requests.

Diffstat:
include/kore/kore.h | 1+
src/worker.c | 23++++++++++++++++-------
2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/include/kore/kore.h b/include/kore/kore.h @@ -530,6 +530,7 @@ void kore_signal(int); void kore_signal_setup(void); void kore_worker_wait(int); void kore_worker_init(void); +void kore_worker_make_busy(void); void kore_worker_shutdown(void); void kore_worker_dispatch_signal(int); void kore_worker_spawn(u_int16_t, u_int16_t); diff --git a/src/worker.c b/src/worker.c @@ -72,8 +72,8 @@ struct wlock { static int worker_trylock(void); static void worker_unlock(void); -static inline int kore_worker_acceptlock_obtain(u_int64_t); -static inline int kore_worker_acceptlock_release(u_int64_t); +static inline int worker_acceptlock_obtain(u_int64_t); +static inline int worker_acceptlock_release(u_int64_t); #if !defined(KORE_NO_TLS) static void worker_entropy_recv(struct kore_msg *, const void *); @@ -290,7 +290,7 @@ kore_worker_entry(struct kore_worker *kw) char buf[16]; int quit, had_lock, r; u_int64_t timerwait, netwait; - u_int64_t now, next_lock, next_prune; + u_int64_t now, next_prune, next_lock; #if !defined(KORE_NO_TLS) u_int64_t last_seed; #endif @@ -403,7 +403,7 @@ kore_worker_entry(struct kore_worker *kw) #endif if (!worker->has_lock && next_lock <= now) { - if (kore_worker_acceptlock_obtain(now)) { + if (worker_acceptlock_obtain(now)) { if (had_lock == 0) { kore_platform_enable_accept(); had_lock = 1; @@ -430,7 +430,7 @@ kore_worker_entry(struct kore_worker *kw) if (worker->has_lock && r > 0) { if (netwait > 10) now = kore_time_ms(); - if (kore_worker_acceptlock_release(now)) + if (worker_acceptlock_release(now)) next_lock = now + WORKER_LOCK_TIMEOUT; } @@ -559,8 +559,17 @@ kore_worker_wait(int final) } } +void +kore_worker_make_busy(void) +{ + if (worker->has_lock) { + worker_unlock(); + worker->has_lock = 0; + } +} + static inline int -kore_worker_acceptlock_release(u_int64_t now) +worker_acceptlock_release(u_int64_t now) { if (worker_count == WORKER_SOLO_COUNT || worker_no_lock == 1) return (0); @@ -589,7 +598,7 @@ kore_worker_acceptlock_release(u_int64_t now) } static inline int -kore_worker_acceptlock_obtain(u_int64_t now) +worker_acceptlock_obtain(u_int64_t now) { int r;