Repository: dotnet/runtime
File: src/coreclr/nativeaot/Runtime/threadstore.h (C/C++)

Code before:
    Crst                m_Lock;

private:
    ThreadStore();

public:
    void                    LockThreadStore();
    void                    UnlockThreadStore();

public:
    class Iterator
    {
        PTR_Thread                      m_pCurrentPosition;
    public:
        Iterator();
        ~Iterator();
        PTR_Thread GetNext();
    };

    ~ThreadStore();
    static ThreadStore *    Create(RuntimeInstance * pRuntimeInstance);
    static Thread *         RawGetCurrentThread();
    static Thread *         GetCurrentThread();
    static Thread *         GetCurrentThreadIfAvailable();
    static Thread *         GetCurrentThreadIfAvailableAsyncSafe();
    static PTR_Thread       GetSuspendingThread();
    static void             AttachCurrentThread();
    static void             AttachCurrentThread(bool fAcquireThreadStoreLock);
    static void             DetachCurrentThread();
#ifndef DACCESS_COMPILE
    static void             SaveCurrentThreadOffsetForDAC();
#else
    static PTR_Thread       GetThreadFromTEB(TADDR pvTEB);
#endif

    void        Destroy();
    void        SuspendAllThreads(bool waitForGCEvent);
    void        ResumeAllThreads(bool waitForGCEvent);

    static bool IsTrapThreadsRequested();
};
typedef DPTR(ThreadStore) PTR_ThreadStore;

ThreadStore * GetThreadStore();

#define FOREACH_THREAD(p_thread_name)                       \
{                                                           \
    ThreadStore::Iterator __threads;                        \
    Thread * p_thread_name;                                 \
    while ((p_thread_name = __threads.GetNext()) != NULL)   \
    {                                                       \

Review comment (suggestion):
The declaration of GetCurrentThreadIfAvailableAsyncSafe at line 50 is unconditional, but the implementation in threadstore.cpp is only provided for TARGET_UNIX && !TARGET_WASM builds. This could cause linker errors on Windows builds if this method is ever called from Windows code. The declaration should be conditionally compiled with the same preprocessor conditions as the implementation.
```suggestion
    static Thread *         GetCurrentThreadIfAvailable();
#if defined(TARGET_UNIX) && !defined(TARGET_WASM)
    static Thread *         GetCurrentThreadIfAvailableAsyncSafe();
#endif
```

Code after:
    Crst                m_Lock;

private:
    ThreadStore();

public:
    void                    LockThreadStore();
    void                    UnlockThreadStore();

public:
    class Iterator
    {
        PTR_Thread                      m_pCurrentPosition;
    public:
        Iterator();
        ~Iterator();
        PTR_Thread GetNext();
    };

    ~ThreadStore();
    static ThreadStore *    Create(RuntimeInstance * pRuntimeInstance);
    static Thread *         RawGetCurrentThread();
    static Thread *         GetCurrentThread();
    static Thread *         GetCurrentThreadIfAvailable();
#if defined(TARGET_UNIX) && !defined(TARGET_WASM)
    static Thread *         GetCurrentThreadIfAvailableAsyncSafe();
#endif
    static PTR_Thread       GetSuspendingThread();
    static void             AttachCurrentThread();
    static void             AttachCurrentThread(bool fAcquireThreadStoreLock);
    static void             DetachCurrentThread();
#ifndef DACCESS_COMPILE
    static void             SaveCurrentThreadOffsetForDAC();
#else
    static PTR_Thread       GetThreadFromTEB(TADDR pvTEB);
#endif

    void        Destroy();
    void        SuspendAllThreads(bool waitForGCEvent);
    void        ResumeAllThreads(bool waitForGCEvent);

    static bool IsTrapThreadsRequested();
};
typedef DPTR(ThreadStore) PTR_ThreadStore;

ThreadStore * GetThreadStore();

#define FOREACH_THREAD(p_thread_name)                       \
{                                                           \
    ThreadStore::Iterator __threads;                        \
    Thread * p_thread_name;                                 \