1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) Microsoft Corporation. All rights reserved. */ 4 /* */ 5 /* This software is licensed under the Microsoft Software License */ 6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8 /* and in the root directory of this software. */ 9 /* */ 10 /**************************************************************************/ 11 12 13 /**************************************************************************/ 14 /**************************************************************************/ 15 /** */ 16 /** ThreadX Component */ 17 /** */ 18 /** Thread */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 24 #define TX_SOURCE_CODE 25 #define TX_THREAD_SMP_SOURCE_CODE 26 27 28 /* Include necessary system files. */ 29 30 #include "tx_api.h" 31 #include "tx_thread.h" 32 #include "tx_timer.h" 33 34 35 /**************************************************************************/ 36 /* */ 37 /* FUNCTION RELEASE */ 38 /* */ 39 /* _tx_thread_smp_unprotect SMP/Linux/GCC */ 40 /* 6.1 */ 41 /* AUTHOR */ 42 /* */ 43 /* William E. Lamie, Microsoft Corporation */ 44 /* */ 45 /* DESCRIPTION */ 46 /* */ 47 /* This function releases previously obtained protection. The supplied */ 48 /* previous interrupt posture is restored. */ 49 /* */ 50 /* INPUT */ 51 /* */ 52 /* Previous interrupt posture */ 53 /* */ 54 /* OUTPUT */ 55 /* */ 56 /* None */ 57 /* */ 58 /* CALLS */ 59 /* */ 60 /* pthread_self */ 61 /* */ 62 /* CALLED BY */ 63 /* */ 64 /* ThreadX Source */ 65 /* */ 66 /* RELEASE HISTORY */ 67 /* */ 68 /* DATE NAME DESCRIPTION */ 69 /* */ 70 /* 09-30-2020 William E. Lamie Initial Version 6.1 */ 71 /* */ 72 /**************************************************************************/ _tx_thread_smp_unprotect(UINT new_interrupt_posture)73void _tx_thread_smp_unprotect(UINT new_interrupt_posture) 74 { 75 76 UINT core; 77 pthread_t current_thread_id; 78 79 /* Lock Linux mutex. */ 80 _tx_linux_mutex_obtain(&_tx_linux_mutex); 81 82 /* Pickup the current thread ID. */ 83 current_thread_id = pthread_self(); 84 85 /* Pickup the current core. */ 86 core = _tx_thread_smp_core_get(); 87 88 /* Determine if this core owns the protection. */ 89 if (_tx_thread_smp_protection.tx_thread_smp_protect_core == core) 90 { 91 92 /* Yes, this core owns the protection. */ 93 94 /* Decrement the protection count. */ 95 _tx_thread_smp_protection.tx_thread_smp_protect_count--; 96 97 /* Is the protection still in force? */ 98 if (_tx_thread_smp_protection.tx_thread_smp_protect_count == 0) 99 { 100 101 /* Restore the global interrupt disable value. */ 102 _tx_linux_global_int_disabled_flag = new_interrupt_posture; 103 104 /* Determine if the preemption disable flag is set. */ 105 if (_tx_thread_preempt_disable == 0) 106 { 107 108 /* Release the protection. */ 109 110 /* Indicate the protection is no longer in force. */ 111 _tx_thread_smp_protection.tx_thread_smp_protect_in_force = TX_FALSE; 112 _tx_thread_smp_protection.tx_thread_smp_protect_thread = TX_NULL; 113 _tx_thread_smp_protection.tx_thread_smp_protect_core = 0xFFFFFFFF; 114 _tx_thread_smp_protection.tx_thread_smp_protect_linux_thread_id = 0; 115 116 /* Debug entry. */ 117 _tx_linux_debug_entry_insert("UNPROTECT-keep", __FILE__, __LINE__); 118 } 119 else 120 { 121 122 /* Debug entry. */ 123 _tx_linux_debug_entry_insert("UNPROTECT-released", __FILE__, __LINE__); 124 } 125 } 126 else 127 { 128 129 /* Debug entry. */ 130 _tx_linux_debug_entry_insert("UNPROTECT-nested", __FILE__, __LINE__); 131 } 132 133 /* Only release the critical section. */ 134 _tx_linux_mutex_release(&_tx_linux_mutex); 135 } 136 137 /* Release the critical section. */ 138 _tx_linux_mutex_release(&_tx_linux_mutex); 139 140 } 141