/***************************************************************************
 * Copyright (C) 2026 Eclipse ThreadX contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * AI Disclosure: This file was largely AI-generated by Codex (gpt 5.4).
 * The AI-generated portions may be considered public domain (CC0-1.0)
 * and not subject to the project's licence. The human contributor has
 * reviewed and verified that the code is correct.
 *
 * SPDX-License-Identifier: MIT and CC0-1.0
 **************************************************************************/

// Some portions generated by Codex (gpt 5.4).

#define TX_SOURCE_CODE
#define TX_THREAD_SMP_SOURCE_CODE

#include "tx_api.h"
#include "tx_thread.h"
#include "tx_timer.h"

ULONG  _tx_thread_smp_current_state_get(void)
{
UINT    core;
DWORD   thread_id;
UINT    critical_section_owned;
ULONG   current_state;

    thread_id =  GetCurrentThreadId();
    critical_section_owned =  (UINT) (_tx_win32_critical_section.tx_win32_critical_section_owner == thread_id);

    if (critical_section_owned == TX_FALSE)
    {
        _tx_win32_critical_section_obtain(&_tx_win32_critical_section);
    }

    core =  _tx_win32_smp_current_core_get();
    current_state =  _tx_thread_system_state[core];

    if (critical_section_owned == TX_FALSE)
    {
        _tx_win32_critical_section_release(&_tx_win32_critical_section);
    }

    return(current_state);
}
