1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include "failguard.h"
#include "libusbemu_threads.h"
int ThreadFailGuardProc(void* params);
namespace libusbemu
{
namespace failguard
{
static volatile bool boTriggered (false);
static QuickEvent hReaction;
static volatile int nDecision (0);
const bool Check()
{
if (failguard::boTriggered)
return(true);
// CTRL + ALT pressed?
if ((GetKeyState(VK_CONTROL) & 0x8000) && (GetKeyState(VK_MENU) & 0x8000))
{
// only one thread is allowed to activate the guard
static QuickMutex mutexFailGuard;
if (mutexFailGuard.TryEnter())
{
if (!failguard::boTriggered)
{
failguard::hReaction.Reset();
failguard::boTriggered = true;
new QuickThread(ThreadFailGuardProc, NULL, true);
}
mutexFailGuard.Leave();
}
}
return(failguard::boTriggered);
}
void WaitDecision()
{
failguard::hReaction.Wait();
}
const bool Abort()
{
return(-1 == nDecision);
}
}
}
using namespace libusbemu::failguard;
int ThreadFailGuardProc(void* params)
{
int user_option =
MessageBoxA(GetDesktopWindow(),
"The libusb_handle_events() fail guard of libusbemu was reached!\n"
"This was caused by pressing and holding the [CTRL] + [ALT] keys.\n"
"If it was unintentional, click Cancel to resume normal execution;\n"
"otherwise, click OK to effectively terminate the thread (note that\n"
"the host program might run abnormally after such termination).",
"WARNING: libusbemu thread fail guard reached!", MB_ICONWARNING | MB_OKCANCEL);
if (IDOK == user_option)
nDecision = -1;
else
boTriggered = false;
hReaction.Signal();
return(0);
}
|