A few tweaks to LockedWrapper locking
This commit is contained in:
@@ -52,8 +52,6 @@ uint32 AIntegrationGameModeBase::Run()
|
|||||||
|
|
||||||
void AIntegrationGameModeBase::ResetToInitialState()
|
void AIntegrationGameModeBase::ResetToInitialState()
|
||||||
{
|
{
|
||||||
FLockedWrapper w(LockableWrapper);
|
|
||||||
|
|
||||||
// Shut down the thread and release the ThreadEvent
|
// Shut down the thread and release the ThreadEvent
|
||||||
if (Thread != nullptr)
|
if (Thread != nullptr)
|
||||||
{
|
{
|
||||||
@@ -66,6 +64,10 @@ void AIntegrationGameModeBase::ResetToInitialState()
|
|||||||
}
|
}
|
||||||
ThreadStopRequested = false;
|
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.
|
// Release and close all sockets.
|
||||||
if (Sockets != nullptr)
|
if (Sockets != nullptr)
|
||||||
{
|
{
|
||||||
@@ -146,15 +148,20 @@ void AIntegrationGameModeBase::BeginPlay()
|
|||||||
{
|
{
|
||||||
Super::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);
|
FLockedWrapper w(LockableWrapper);
|
||||||
|
|
||||||
// Sanity checks.
|
// Sanity checks. Make sure everything is clean.
|
||||||
checkf(Thread == nullptr, TEXT("There should be no thread here."));
|
checkf(Thread == nullptr, TEXT("There should be no thread here."));
|
||||||
checkf(w->engine == nullptr, TEXT("There should be no engine 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.
|
// Try to initialize the wrapper.
|
||||||
w.InitWrapper();
|
w.InitWrapper();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user