From f5ed565912f71ec8cd6953192f052f7f61964ddb Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Tue, 7 Sep 2021 14:12:31 +0200 Subject: [PATCH] Don't waste time spinning on a mutex that cannot be unlocked, yield as it may be unlocked by another process, if not then whenever we get back here try again (repeat if same result), else fall through with lock, execute event loop, unlock and yield (as per normal) --- source/eventy/engine.d | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/source/eventy/engine.d b/source/eventy/engine.d index 6ec302a..1c5f440 100644 --- a/source/eventy/engine.d +++ b/source/eventy/engine.d @@ -109,8 +109,22 @@ public final class Engine : Thread { /* TODO: Implement me */ - /* Lock the queue-set */ - queueLock.lock(); + /** + * TODO: If lock fails, then yield + */ + + /** + * Lock the queue-set + * + * Additionally: + * Don't waste time spinning on mutex, + * if it is not lockable then yield + */ + while(!queueLock.tryLock_nothrow()) + { + yield(); + } + foreach(Queue queue; queues) {