2021-06-27 21:25:29 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: RuntimeInternal.hpp
|
|
|
|
Date: 2021-6-12
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
2022-01-26 00:01:06 +00:00
|
|
|
//#include <AuroraCommon.hpp>
|
|
|
|
#include <AuroraEnvironment.h>
|
2021-06-27 21:25:29 +00:00
|
|
|
|
|
|
|
#if defined(AURORA_PLATFORM_WIN32)
|
|
|
|
#if !defined(NOMINMAX)
|
|
|
|
#define NOMINMAX
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(WIN32_LEAN_AND_MEAN)
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
|
|
|
|
2022-12-14 01:35:18 +00:00
|
|
|
#define _WIN32_WINNT 0x0601
|
2021-06-27 21:25:29 +00:00
|
|
|
#include <SDKDDKVer.h>
|
|
|
|
|
2022-03-10 15:35:01 +00:00
|
|
|
#include <winsock2.h>
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
#if defined(_AUHAS_ASIO)
|
|
|
|
#include <asio.hpp>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#else
|
|
|
|
#if defined(_AUHAS_ASIO)
|
|
|
|
#include <asio.hpp>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
#if defined(AURORA_IS_POSIX_DERIVED)
|
2021-06-27 21:25:29 +00:00
|
|
|
#define AURORA_HAS_PTHREADS
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
#define _FILE_OFFSET_BITS 64
|
2021-10-02 16:07:33 +00:00
|
|
|
#if !defined(_LARGEFILE64_SOURCE)
|
|
|
|
#define _LARGEFILE64_SOURCE
|
|
|
|
#endif
|
2021-09-06 10:58:08 +00:00
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
#include <pthread.h>
|
2022-04-04 07:53:34 +00:00
|
|
|
#include <semaphore.h>
|
2021-10-02 16:07:33 +00:00
|
|
|
#include <signal.h>
|
2021-09-06 10:58:08 +00:00
|
|
|
#include <stdlib.h>
|
2021-10-02 16:07:33 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#define stricmp strcasecmp
|
2022-04-05 01:19:37 +00:00
|
|
|
|
|
|
|
#if defined(AURORA_IS_LINUX_DERIVED)
|
|
|
|
#include <sys/eventfd.h>
|
|
|
|
#endif
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
#endif
|
|
|
|
|
2022-06-11 23:01:27 +00:00
|
|
|
#define GIMME_IOWAITABLEITEM
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
#include <AuroraRuntime.hpp>
|
|
|
|
|
|
|
|
inline Aurora::RuntimeStartInfo gRuntimeConfig;
|
2022-08-14 11:01:54 +00:00
|
|
|
inline int gRuntimeRunLevel {0};
|
2021-06-27 21:25:29 +00:00
|
|
|
|
2022-08-14 11:01:54 +00:00
|
|
|
|
|
|
|
using namespace Aurora::Logging;
|
|
|
|
|
|
|
|
namespace Aurora
|
|
|
|
{
|
|
|
|
#if defined(AU_CFG_ID_DEBUG)
|
|
|
|
static const bool kIsDebugBuild = true;
|
|
|
|
#else
|
|
|
|
static const bool kIsDebugBuild = false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool RuntimeIsMainThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
#define RUNTIME_ASSERT_SHUTDOWN_SAFE(value, ...) \
|
|
|
|
if (gRuntimeRunLevel < 3) \
|
|
|
|
{ \
|
|
|
|
SysAssert(value, __VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
if (!bool(value)) \
|
|
|
|
{ \
|
|
|
|
try \
|
|
|
|
{ \
|
|
|
|
AuLogWarn("Error while shutting down: {}", fmt::format(__VA_ARGS__)); \
|
|
|
|
} \
|
|
|
|
catch (...) {} \
|
|
|
|
if (!kIsDebugBuild) SysPushErrorGeneric(__VA_ARGS__); \
|
|
|
|
if (RuntimeIsMainThread()) \
|
|
|
|
{ \
|
|
|
|
if (gRuntimeRunLevel < /*5*/ 4 /*i dont like this and i think i know the problem*/) \
|
|
|
|
{ \
|
|
|
|
SysPanic("Error while shutting down: {}", fmt::format(__VA_ARGS__));\
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
Threading::Threads::TerminateCurrent(); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|