/*** Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: AuGrugThread.cpp Date: 2022-02-03 Author: Reece ***/ #include #include "AuGrug.hpp" #include "AuGrugThread.hpp" #include namespace Aurora::Grug { GrugThread::GrugThread() { #if defined(AURORA_IS_MODERNNT_DERIVED) nt.pThread = AuThreads::GetThread(); // not signal safe, but we arent in posix land #endif #if defined(AURORA_IS_POSIX_DERIVED) // idnt by active ttid only posix.pid = gettid(); #else // posix signal rules dont apply genericThreadHandle = AuThreads::GetThreadId(); #endif } AuThreads::IAuroraThread *GrugThread::ToThread() const { #if defined(AURORA_IS_MODERNNT_DERIVED) if (nt.pThread) { return nt.pThread; } #endif #if defined(AURORA_IS_POSIX_DERIVED) if (posix.pid >= 0) { auto pThread = AuThreads::GetThreadByPOSIXPid(posix.pid); if (pThread) { return pThread; } } #endif return AuThreads::GetThreadByOSHandle(genericThreadHandle); } }