|
|
@ -99,6 +99,7 @@ func (event * BaseEvent) Lock() error {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
lock_err = true
|
|
|
|
lock_err = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
locked_resources = append(locked_resources, resource)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if lock_err == true {
|
|
|
|
if lock_err == true {
|
|
|
@ -111,6 +112,12 @@ func (event * BaseEvent) Lock() error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (event * BaseEvent) Unlock() 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)
|
|
|
|
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) {
|
|
|
|
queue.actions["queue_event"] = func() (string, error) {
|
|
|
|
// Sort the list of events by priority
|
|
|
|
// Copy the events to sort the list
|
|
|
|
// 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"
|
|
|
|
|
|
|
|
copied_events := make([]Event, len(queue.Children()))
|
|
|
|
copied_events := make([]Event, len(queue.Children()))
|
|
|
|
copy(copied_events, queue.Children())
|
|
|
|
copy(copied_events, queue.Children())
|
|
|
|
less := func(i int, j int) bool {
|
|
|
|
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) {
|
|
|
|
go func(event Event, info * EventQueueInfo, queue * EventQueue) {
|
|
|
|
event.Run()
|
|
|
|
event.Run()
|
|
|
|
info.state = "done"
|
|
|
|
info.state = "done"
|
|
|
|
|
|
|
|
event.Unlock()
|
|
|
|
queue.signal <- "event_done"
|
|
|
|
queue.signal <- "event_done"
|
|
|
|
}(event, info, queue)
|
|
|
|
}(event, info, queue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|