summaryrefslogtreecommitdiff
path: root/ports_smp/win64/vs_2022/src/tx_thread_smp_unprotect.c
blob: b845767d9a09a32ab3d19303912efd6268cb2b6d (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
/***************************************************************************
 * 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_unprotect(UINT new_interrupt_posture)
{
UINT    core;
DWORD   current_thread_id;
UINT    critical_section_owned;

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

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

    core =  _tx_thread_smp_core_get();

    if (_tx_thread_smp_protection.tx_thread_smp_protect_core == core)
    {
        _tx_thread_smp_protection.tx_thread_smp_protect_count--;

        if (_tx_thread_smp_protection.tx_thread_smp_protect_count == 0U)
        {
            _tx_win32_global_int_disabled_flag =  new_interrupt_posture;

            if (_tx_thread_preempt_disable == 0U)
            {
                _tx_thread_smp_protection.tx_thread_smp_protect_in_force =   TX_FALSE;
                _tx_thread_smp_protection.tx_thread_smp_protect_thread =     TX_NULL;
                _tx_thread_smp_protection.tx_thread_smp_protect_core =       0xFFFFFFFFUL;
                _tx_thread_smp_protection.tx_thread_smp_protect_thread_id =  0U;
                _tx_win32_debug_entry_insert("UNPROTECT-keep", __FILE__, __LINE__);
            }
            else
            {
                _tx_win32_debug_entry_insert("UNPROTECT-released", __FILE__, __LINE__);
            }
        }
        else
        {
            _tx_win32_debug_entry_insert("UNPROTECT-nested", __FILE__, __LINE__);
        }

        _tx_win32_critical_section_release(&_tx_win32_critical_section);
    }
    else
    {
        _tx_win32_critical_section_release(&_tx_win32_critical_section);
    }
}