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_current_state_get SMP/Linux/GCC */ 40 /* 6.1 */ 41 /* AUTHOR */ 42 /* */ 43 /* William E. Lamie, Microsoft Corporation */ 44 /* */ 45 /* DESCRIPTION */ 46 /* */ 47 /* This function is gets the current state of the calling core. */ 48 /* */ 49 /* INPUT */ 50 /* */ 51 /* None */ 52 /* */ 53 /* OUTPUT */ 54 /* */ 55 /* None */ 56 /* */ 57 /* CALLS */ 58 /* */ 59 /* pthread_self Get Linux thread ID */ 60 /* _tx_linux_mutex_obtain */ 61 /* _tx_linux_mutex_release */ 62 /* */ 63 /* CALLED BY */ 64 /* */ 65 /* ThreadX Components */ 66 /* */ 67 /* RELEASE HISTORY */ 68 /* */ 69 /* DATE NAME DESCRIPTION */ 70 /* */ 71 /* 09-30-2020 William E. Lamie Initial Version 6.1 */ 72 /* */ 73 /**************************************************************************/ _tx_thread_smp_current_state_get(void)74ULONG _tx_thread_smp_current_state_get(void) 75 { 76 77 UINT core; 78 UINT i; 79 ULONG current_state; 80 pthread_t thread_id; 81 82 83 /* Lock Linux mutex. */ 84 _tx_linux_mutex_obtain(&_tx_linux_mutex); 85 86 /* Default to core 0 for ISRs and initialization. */ 87 core = 0; 88 89 /* Pickup the currently executing thread ID. */ 90 thread_id = pthread_self(); 91 92 /* Loop through mapping table to find the core running this thread ID. */ 93 for (i = 0; i < TX_THREAD_SMP_MAX_CORES; i++) 94 { 95 96 /* Does this core match? */ 97 if (_tx_linux_virtual_cores[i].tx_thread_smp_core_mapping_linux_thread_id == thread_id) 98 { 99 100 /* Yes, we have a match. */ 101 core = i; 102 103 /* Get out of loop. */ 104 break; 105 } 106 } 107 108 /* Pickup the current state. */ 109 current_state = _tx_thread_system_state[core]; 110 111 /* Unlock linux mutex. */ 112 _tx_linux_mutex_release(&_tx_linux_mutex); 113 114 /* Now return the state for the core. */ 115 return(current_state); 116 } 117 118 119 120