From 8da3dd2b4aa55ccb3a893ec6483b234f1dc20575 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Tue, 31 Aug 2021 11:39:41 +0200 Subject: [PATCH] Loop through queue and find matcxhing signal handlers for the first event of each queue --- source/eventy/engine.d | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/source/eventy/engine.d b/source/eventy/engine.d index 2d8e7bc..02dd551 100644 --- a/source/eventy/engine.d +++ b/source/eventy/engine.d @@ -42,10 +42,52 @@ public final class Engine { /* TODO: Implement me */ + /* Lock the queue-set */ + queueLock.lock(); + + foreach(Queue queue; queues) + { + /* If the queue has evenets queued */ + if(queue.hasEvents()) + { + /* TODO: Add different dequeuing techniques */ + + /* Pop the first Event */ + Event headEvent = queue.popEvent(); + + /* Get all signal-handlers for this event type */ + Signal[] handlersMatched = getSignalsForEvent(headEvent); + + } + } + + /* Unlock the queue set */ + queueLock.unlock(); + /* TODO: Add yield to stop mutex starvation on a single thread */ } } + private Signal[] getSignalsForEvent(Event e) + { + /* Matched handlers */ + Signal[] matchedHandlers; + + /* Lock the signal-set */ + handlerLock.lock(); + + /* Find all handlers matching */ + foreach(Signal signal; handlers) + { + matchedHandlers ~= signal; + } + + /* Unlock the signal-set */ + handlerLock.unlock(); + + return matchedHandlers; + } + /** * push(Event e) *