summaryrefslogtreecommitdiff
path: root/ports_smp/win64/vs_2022/src/tx_thread_interrupt_control.c
blob: b596baeb4ad4c7b3b378d1f744d26ef3e467fd93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/***************************************************************************
 * 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_thread.h"

UINT  _tx_thread_interrupt_disable(void)
{
UINT    previous_value;

    previous_value =  _tx_thread_interrupt_control(TX_INT_DISABLE);
    return(previous_value);
}


VOID  _tx_thread_interrupt_restore(UINT previous_posture)
{
    previous_posture =  _tx_thread_interrupt_control(previous_posture);
    TX_PARAMETER_NOT_USED(previous_posture);
}


UINT  _tx_thread_interrupt_control(UINT new_posture)
{
UINT        old_posture;
TX_THREAD   *thread_ptr;
DWORD       thread_id;
UINT        core;

    _tx_win32_critical_section_obtain(&_tx_win32_critical_section);

#ifdef TX_WIN32_DEBUG_ENABLE
    if (new_posture == TX_INT_ENABLE)
    {
        _tx_win32_debug_entry_insert("RESTORE", __FILE__, __LINE__);
    }
    else
    {
        _tx_win32_debug_entry_insert("DISABLE", __FILE__, __LINE__);
    }
#endif

    thread_id =  GetCurrentThreadId();
    core =       _tx_thread_smp_core_get();
    thread_ptr = _tx_thread_current_ptr[core];

    if ((_tx_win32_threadx_thread != 0) &&
        ((thread_ptr == TX_NULL) || (thread_ptr -> tx_thread_win32_thread_id != thread_id)))
    {
        _tx_win32_critical_section_release_all(&_tx_win32_critical_section);
        ExitThread(0);
    }

    if (_tx_win32_critical_section.tx_win32_critical_section_nested_count == 1U)
    {
        old_posture =  TX_INT_ENABLE;
    }
    else
    {
        old_posture =  TX_INT_DISABLE;
    }

    if (_tx_thread_system_state[core] != 0UL)
    {
        if (new_posture == TX_INT_ENABLE)
        {
            _tx_win32_global_int_disabled_flag =  TX_FALSE;
            _tx_win32_critical_section_release_all(&_tx_win32_critical_section);
        }
        else if (new_posture == TX_INT_DISABLE)
        {
            _tx_win32_global_int_disabled_flag =  TX_TRUE;
        }
    }
    else if (thread_ptr != TX_NULL)
    {
        if (new_posture == TX_INT_ENABLE)
        {
            thread_ptr -> tx_thread_win32_int_disabled_flag =  TX_FALSE;
            _tx_win32_critical_section_release_all(&_tx_win32_critical_section);
        }
        else if (new_posture == TX_INT_DISABLE)
        {
            thread_ptr -> tx_thread_win32_int_disabled_flag =  TX_TRUE;
        }
    }

    return(old_posture);
}