Files
UnrealEngineUWP/Engine/Source/Developer/Windows/LiveCoding/Private/External/LC_Restart.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

79 lines
2.1 KiB
C++

// Copyright 2011-2019 Molecular Matters GmbH, all rights reserved.
#include "LC_Restart.h"
#include "LC_Event.h"
#include "LC_PrimitiveNames.h"
#include "LC_Process.h"
#include "LC_Memory.h"
namespace
{
static Event* g_requestRestart = nullptr;
static Event* g_restartPrepared = nullptr;
static Event* g_executeRestart = nullptr;
}
void restart::Startup(void)
{
const unsigned int processId = process::GetId();
g_requestRestart = new Event(primitiveNames::RequestRestart(processId).c_str(), Event::Type::AUTO_RESET);
g_restartPrepared = new Event(primitiveNames::PreparedRestart(processId).c_str(), Event::Type::AUTO_RESET);
g_executeRestart = new Event(primitiveNames::Restart(processId).c_str(), Event::Type::AUTO_RESET);
}
void restart::Shutdown(void)
{
memory::DeleteAndNull(g_requestRestart);
memory::DeleteAndNull(g_restartPrepared);
memory::DeleteAndNull(g_executeRestart);
}
int restart::WasRequested(void)
{
// check if the host requested a restart
if (g_requestRestart->TryWait())
{
return 1;
}
return 0;
}
void restart::Execute(lpp::RestartBehaviour behaviour, unsigned int exitCode)
{
// tell the host that we finished running any custom client code and prepared everything for a restart
g_restartPrepared->Signal();
// wait until the host tells us to restart
g_executeRestart->Wait();
switch (behaviour)
{
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-exitprocess
case lpp::LPP_RESTART_BEHAVIOUR_DEFAULT_EXIT:
ExitProcess(exitCode);
break;
// https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/exit-exit-exit?view=vs-2019
case lpp::LPP_RESTART_BEHAVIOUR_EXIT_WITH_FLUSH:
exit(static_cast<int>(exitCode));
break;
// https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/exit-exit-exit?view=vs-2019
case lpp::LPP_RESTART_BEHAVIOUR_EXIT:
_Exit(static_cast<int>(exitCode));
break;
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-terminateprocess
case lpp::LPP_RESTART_BEHAVIOUR_INSTANT_TERMINATION:
::TerminateProcess(::GetCurrentProcess(), exitCode);
break;
};
}