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

void  _tx_thread_smp_core_preempt(UINT core)
{
TX_THREAD   *preempt_thread;

    preempt_thread =  _tx_thread_current_ptr[core];

    if (preempt_thread != TX_NULL)
    {
        preempt_thread -> tx_thread_win32_deferred_preempt =  TX_TRUE;
        _tx_win32_debug_entry_insert("CORE_PREEMPT_deferred", __FILE__, __LINE__);

        MemoryBarrier();
        if (SetEvent(_tx_win32_scheduler_event) == 0)
        {
            _tx_win32_system_error++;
        }
    }
    else if (_tx_thread_execute_ptr[core] != TX_NULL)
    {
        _tx_win32_debug_entry_insert("CORE_PREEMPT_wake_idle", __FILE__, __LINE__);

        MemoryBarrier();
        if (SetEvent(_tx_win32_scheduler_event) == 0)
        {
            _tx_win32_system_error++;
        }
    }
}
