1 /*************************************************************************** 2 * Copyright (c) 2024 Microsoft Corporation 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the MIT License which is available at 6 * https://opensource.org/licenses/MIT. 7 * 8 * SPDX-License-Identifier: MIT 9 **************************************************************************/ 10 11 12 /**************************************************************************/ 13 /**************************************************************************/ 14 /** */ 15 /** ThreadX Component */ 16 /** */ 17 /** Thread */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 23 #define TX_SOURCE_CODE 24 #define TX_THREAD_SMP_SOURCE_CODE 25 26 27 /* Include necessary system files. */ 28 29 #include "tx_api.h" 30 #include "tx_thread.h" 31 #include "tx_timer.h" 32 33 34 /**************************************************************************/ 35 /* */ 36 /* FUNCTION RELEASE */ 37 /* */ 38 /* _tx_thread_smp_current_state_get SMP/Linux/GCC */ 39 /* 6.1 */ 40 /* AUTHOR */ 41 /* */ 42 /* William E. Lamie, Microsoft Corporation */ 43 /* */ 44 /* DESCRIPTION */ 45 /* */ 46 /* This function is gets the current state of the calling core. */ 47 /* */ 48 /* INPUT */ 49 /* */ 50 /* None */ 51 /* */ 52 /* OUTPUT */ 53 /* */ 54 /* None */ 55 /* */ 56 /* CALLS */ 57 /* */ 58 /* pthread_self Get Linux thread ID */ 59 /* _tx_linux_mutex_obtain */ 60 /* _tx_linux_mutex_release */ 61 /* */ 62 /* CALLED BY */ 63 /* */ 64 /* ThreadX Components */ 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_current_state_get(void)73ULONG _tx_thread_smp_current_state_get(void) 74 { 75 76 UINT core; 77 UINT i; 78 ULONG current_state; 79 pthread_t thread_id; 80 81 82 /* Lock Linux mutex. */ 83 _tx_linux_mutex_obtain(&_tx_linux_mutex); 84 85 /* Default to core 0 for ISRs and initialization. */ 86 core = 0; 87 88 /* Pickup the currently executing thread ID. */ 89 thread_id = pthread_self(); 90 91 /* Loop through mapping table to find the core running this thread ID. */ 92 for (i = 0; i < TX_THREAD_SMP_MAX_CORES; i++) 93 { 94 95 /* Does this core match? */ 96 if (_tx_linux_virtual_cores[i].tx_thread_smp_core_mapping_linux_thread_id == thread_id) 97 { 98 99 /* Yes, we have a match. */ 100 core = i; 101 102 /* Get out of loop. */ 103 break; 104 } 105 } 106 107 /* Pickup the current state. */ 108 current_state = _tx_thread_system_state[core]; 109 110 /* Unlock linux mutex. */ 111 _tx_linux_mutex_release(&_tx_linux_mutex); 112 113 /* Now return the state for the core. */ 114 return(current_state); 115 } 116 117 118 119