AuroraRuntime/Source/Threading/Primitives/ThreadCookie.hpp

40 lines
851 B
C++
Raw Normal View History

/***
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
}
}