From a43216210f1c7ecec78d25f062f52bfa6ffc02c9 Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Tue, 20 Feb 2024 18:25:30 -0500 Subject: [PATCH] Fix race condition with DMAPI custom event creation/completion --- src/DMAPI/tgs/v5/api.dm | 5 ++--- src/DMAPI/tgs/v5/topic.dm | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/DMAPI/tgs/v5/api.dm b/src/DMAPI/tgs/v5/api.dm index ffdde1ae20..9b64931f8f 100644 --- a/src/DMAPI/tgs/v5/api.dm +++ b/src/DMAPI/tgs/v5/api.dm @@ -276,13 +276,12 @@ return TRUE TGS_DEBUG_LOG("Waiting for completion of event ID: [event_id]") - pending_events[event_id] = TRUE - do + while(!pending_events[event_id]) sleep(world.tick_lag) - while(pending_events[event_id]) TGS_DEBUG_LOG("Completed wait on event ID: [event_id]") + pending_events -= event_id return TRUE diff --git a/src/DMAPI/tgs/v5/topic.dm b/src/DMAPI/tgs/v5/topic.dm index b13f83f82c..e66edc2720 100644 --- a/src/DMAPI/tgs/v5/topic.dm +++ b/src/DMAPI/tgs/v5/topic.dm @@ -285,7 +285,7 @@ return TopicResponse("Invalid or missing [DMAPI5_EVENT_ID]") TGS_DEBUG_LOG("Completing event ID [event_id]...") - pending_events -= event_id + pending_events[event_id] = TRUE return TopicResponse() return TopicResponse("Unknown command: [command]")