AuroraRuntime/Source/Threading/Primitives/ThreadCookie.hpp
Reece f24a1c1924 [*] im not even going to switch to a cross arch to assume this isnt going to compile
(actually it looked even worse under compiler explorer. this patch is much better)
2023-03-15 03:12:10 +00:00

40 lines
851 B
C++

/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ThreadCookie.hpp
Date: 2023-3-14
Author: Reece
***/
#pragma once
#if defined(AURORA_IS_MODERNNT_DERIVED) && defined(AURORA_IS_64BIT)
extern "C"
{
AuUInt32 GetCurrentThreadIDFast();
}
#endif
namespace Aurora::Threading::Primitives
{
using ThreadCookie_t = AuUInt;
static auline ThreadCookie_t GetThreadCookie()
{
#if defined(AURORA_IS_MODERNNT_DERIVED)
#if defined(AURORA_IS_32BIT)
__asm {
mov eax, fs:[0x18]
mov eax, [eax + 0x24]
ret
}
#else
return ::GetCurrentThreadIDFast();
#endif
#elif defined(AURORA_IS_POSIX_DERIVED)
return (ThreadCookie_t)pthread_self();
#else
return (ThreadCookie_t)Threads::GetThread();
#endif
}
}