Skip to content

Commit

Permalink
Change Native AOT ThreadBuffer.m_threadId to OS thread id (#96075)
Browse files Browse the repository at this point in the history
* Change Native AOT ThreadBuffer.m_threadId to OS thread id.

* Remove the unused IsCurrentThread()

* Code review feedback
  • Loading branch information
mikem8361 authored Dec 16, 2023
1 parent 5d2c901 commit 41b32f8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 16 deletions.
7 changes: 0 additions & 7 deletions src/coreclr/gc/env/gcenv.structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@ struct GCSystemInfo

typedef void * HANDLE;

// Across all platforms, NativeAOT Thread::GetPalThreadIdForLogging assumes that the thread
// ID is stored in the first 8 bytes of this structure.

#ifdef TARGET_UNIX

#ifdef FEATURE_NATIVEAOT
static_assert(sizeof(pthread_t) == sizeof(uint64_t), "EEThreadId layout mismatch");
#endif

class EEThreadId
{
pthread_t m_id;
Expand Down
9 changes: 2 additions & 7 deletions src/coreclr/nativeaot/Runtime/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void Thread::Construct()
m_pDeferredTransitionFrame = TOP_OF_STACK_MARKER;
m_hPalThread = INVALID_HANDLE_VALUE;

m_threadId.SetToCurrentThread();
m_threadId = PalGetCurrentOSThreadId();

HANDLE curProcessPseudo = PalGetCurrentProcess();
HANDLE curThreadPseudo = PalGetCurrentThread();
Expand Down Expand Up @@ -342,12 +342,7 @@ bool Thread::CatchAtSafePoint()

uint64_t Thread::GetPalThreadIdForLogging()
{
return *(uint64_t*)&m_threadId;
}

bool Thread::IsCurrentThread()
{
return m_threadId.IsCurrentThread();
return m_threadId;
}

uint64_t Thread::s_DeadThreadsNonAllocBytes = 0;
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/nativeaot/Runtime/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct ThreadBuffer
GCFrameRegistration* m_pGCFrameRegistrations;
PTR_VOID m_pStackLow;
PTR_VOID m_pStackHigh;
EEThreadId m_threadId; // OS thread ID
uint64_t m_threadId; // OS thread ID
PTR_VOID m_pThreadStressLog; // pointer to head of thread's StressLogChunks
NATIVE_CONTEXT* m_interruptedContext; // context for an asynchronously interrupted thread.
#ifdef FEATURE_SUSPEND_REDIRECTION
Expand Down Expand Up @@ -215,7 +215,6 @@ class Thread : private ThreadBuffer
gc_alloc_context * GetAllocContext();

uint64_t GetPalThreadIdForLogging();
bool IsCurrentThread();

void GcScanRoots(ScanFunc* pfnEnumCallback, ScanContext * pvCallbackData);

Expand Down

0 comments on commit 41b32f8

Please sign in to comment.