From 07097bfd9d046342c429eef95f1c009463913e74 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Tue, 30 May 2023 00:00:14 -0600 Subject: [PATCH] Unlock required resources on event unlock --- event.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/event.go b/event.go index e4a2fdb..77ff38d 100644 --- a/event.go +++ b/event.go @@ -99,6 +99,7 @@ func (event * BaseEvent) Lock() error { if err != nil { lock_err = true } + locked_resources = append(locked_resources, resource) } if lock_err == true { @@ -111,6 +112,12 @@ func (event * BaseEvent) Lock() error { } func (event * BaseEvent) Unlock() error { + for _, resource := range(event.RequiredResources()) { + err := resource.Unlock(event) + if err != nil { + panic(err) + } + } return event.DoneResource().Unlock(event) } @@ -213,11 +220,7 @@ func NewEventQueue(name string, description string, required_resources []Resourc } queue.actions["queue_event"] = func() (string, error) { - // Sort the list of events by priority - // Keep trying to lock the highest priority event until the end of the list is reached, or an event is locked - // If an event is locked, transition it to "started" and start event in a new goroutine - // If the end of the queue is reached and there are no uncompleted events, transition to "done" - // If the end of the queue is reached and there are uncompleted events, transition to "wait" + // Copy the events to sort the list copied_events := make([]Event, len(queue.Children())) copy(copied_events, queue.Children()) less := func(i int, j int) bool { @@ -242,6 +245,7 @@ func NewEventQueue(name string, description string, required_resources []Resourc go func(event Event, info * EventQueueInfo, queue * EventQueue) { event.Run() info.state = "done" + event.Unlock() queue.signal <- "event_done" }(event, info, queue) }