From 57ea8d8574aaa05ca4ac492b26231107f8abb9f8 Mon Sep 17 00:00:00 2001 From: jyelon Date: Sun, 3 Sep 2023 03:40:44 -0400 Subject: [PATCH] A few tweaks to LockedWrapper locking --- .../Integration/IntegrationGameModeBase.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Source/Integration/IntegrationGameModeBase.cpp b/Source/Integration/IntegrationGameModeBase.cpp index 8d2b841b..8d82f981 100644 --- a/Source/Integration/IntegrationGameModeBase.cpp +++ b/Source/Integration/IntegrationGameModeBase.cpp @@ -52,8 +52,6 @@ uint32 AIntegrationGameModeBase::Run() void AIntegrationGameModeBase::ResetToInitialState() { - FLockedWrapper w(LockableWrapper); - // Shut down the thread and release the ThreadEvent if (Thread != nullptr) { @@ -66,6 +64,10 @@ void AIntegrationGameModeBase::ResetToInitialState() } ThreadStopRequested = false; + // Now that the thread's gone, we should be able to + // just claim and hold the lock on the wrapper. + FLockedWrapper w(LockableWrapper); + // Release and close all sockets. if (Sockets != nullptr) { @@ -146,15 +148,20 @@ void AIntegrationGameModeBase::BeginPlay() { Super::BeginPlay(); + // Make sure we're starting from a clean slate. + // Note: this claims the wrapper lock, so don't claim + // the lock before calling this. + ResetToInitialState(); + + // Now we're just going to claim the wrapper + // lock for the remainder. When we create the thread, + // the thread will hang until we release this lock. FLockedWrapper w(LockableWrapper); - // Sanity checks. + // Sanity checks. Make sure everything is clean. checkf(Thread == nullptr, TEXT("There should be no thread here.")); checkf(w->engine == nullptr, TEXT("There should be no engine here.")); - // Make sure we're starting from a clean slate. - ResetToInitialState(); - // Try to initialize the wrapper. w.InitWrapper();