Files
UnrealEngineUWP/Engine/Source/Developer/Windows/LiveCoding/Private/External/LC_SyncPoint.cpp
ben marsh e675e5497c Merging Live++ 1.5.0
#rb none
#jira

#ROBOMERGE-SOURCE: CL 7321355 in //UE4/Release-4.23/...
#ROBOMERGE-BOT: RELEASE (Release-4.23 -> Main) (v371-7306989)

[CL 7321356 by ben marsh in Main branch]
2019-07-16 08:43:32 -04:00

61 lines
1.3 KiB
C++

// Copyright 2011-2019 Molecular Matters GmbH, all rights reserved.
#include "LC_SyncPoint.h"
#include "LC_CriticalSection.h"
#include "LC_Semaphore.h"
namespace
{
static CriticalSection g_syncPointCS;
static volatile bool g_isSyncPointUsed = false;
static Semaphore g_enterUserSyncPoint(0u, 1u);
static Semaphore g_leaveUserSyncPoint(0u, 1u);
static Semaphore g_dllSyncPoint(0u, 1u);
}
void syncPoint::Enter(void)
{
// if the sync point is not used by the user, do nothing
if (!g_isSyncPointUsed)
{
return;
}
// tell user code that we're inside the sync point now, and in turn wait until it has reached its sync point
g_dllSyncPoint.Signal();
g_enterUserSyncPoint.Wait();
}
void syncPoint::Leave(void)
{
// if the sync point is not used by the user, do nothing
if (!g_isSyncPointUsed)
{
return;
}
// tell user code that we're finished
g_leaveUserSyncPoint.Signal();
}
void syncPoint::EnterTarget(void)
{
// mark the sync point as being used as soon as we enter this function the first time
{
CriticalSection::ScopedLock lock(&g_syncPointCS);
g_isSyncPointUsed = true;
}
if (g_dllSyncPoint.TryWait())
{
// DLL code is currently inside sync point. tell DLL code that we are here, and wait for it to leave.
g_enterUserSyncPoint.Signal();
g_leaveUserSyncPoint.Wait();
}
}