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

#define TX_SOURCE_CODE
#define TX_THREAD_SMP_SOURCE_CODE

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

VOID  _tx_timer_interrupt(VOID)
{
UINT    saved_posture;

    saved_posture =  _tx_thread_smp_protect();

    _tx_timer_interrupt_active++;
    _tx_win32_debug_entry_insert("TIMER INTERRUPT", __FILE__, __LINE__);

    _tx_timer_system_clock++;

    if (*_tx_timer_current_ptr)
    {
        _tx_timer_expired =  TX_TRUE;
    }
    else
    {
        _tx_timer_current_ptr++;
        if (_tx_timer_current_ptr == _tx_timer_list_end)
        {
            _tx_timer_current_ptr =  _tx_timer_list_start;
        }
    }

    if (_tx_timer_expired != TX_FALSE)
    {
        _tx_timer_expiration_process();
    }

    _tx_thread_time_slice();

    _tx_timer_interrupt_active++;
    _tx_thread_smp_unprotect(saved_posture);
}
