Files
compute-runtime/offline_compiler/utilities/windows/safety_guard_windows.h
Mateusz Jablonski a48b50c554 Update copyright headers in offline_compiler
Change-Id: Ia07bbb7d53dc2a5f14ba81b1074dff4379742c0c
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
2020-02-22 23:48:51 +01:00

41 lines
975 B
C++

/*
* Copyright (C) 2018-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "core/helpers/abort.h"
#include "offline_compiler/utilities/windows/seh_exception.h"
#include <setjmp.h>
static jmp_buf jmpbuf;
class SafetyGuardWindows {
public:
template <typename T, typename Object, typename Method>
T call(Object *object, Method method, T retValueOnCrash) {
int jump = 0;
jump = setjmp(jmpbuf);
if (jump == 0) {
__try {
return (object->*method)();
} __except (SehException::filter(GetExceptionCode(), GetExceptionInformation())) {
if (onExcept) {
onExcept();
} else {
NEO::abortExecution();
}
longjmp(jmpbuf, 1);
}
}
return retValueOnCrash;
}
typedef void (*callbackFunction)();
callbackFunction onExcept = nullptr;
};