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 #define TX_SOURCE_CODE
24 
25 
26 /* Include necessary system files.  */
27 
28 #include "tx_api.h"
29 #include "tx_thread.h"
30 #ifdef TX_ENABLE_EVENT_TRACE
31 #include "tx_trace.h"
32 #endif
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _tx_thread_identify                                 PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    William E. Lamie, Microsoft Corporation                             */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function returns the control block pointer of the currently    */
47 /*    executing thread.  If the return value is NULL, no thread is        */
48 /*    executing.                                                          */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    None                                                                */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    TX_THREAD *                           Pointer to control block of   */
57 /*                                            currently executing thread  */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    None                                                                */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    Application Code                                                    */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
72 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*                                                                        */
75 /**************************************************************************/
_tx_thread_identify(VOID)76 TX_THREAD  *_tx_thread_identify(VOID)
77 {
78 
79 TX_THREAD       *thread_ptr;
80 
81 TX_INTERRUPT_SAVE_AREA
82 
83 
84     /* Disable interrupts to put the timer on the created list.  */
85     TX_DISABLE
86 
87 #ifdef TX_ENABLE_EVENT_TRACE
88 
89     /* If trace is enabled, insert this event into the trace buffer.  */
90     TX_TRACE_IN_LINE_INSERT(TX_TRACE_THREAD_IDENTIFY, 0, 0, 0, 0, TX_TRACE_THREAD_EVENTS)
91 #endif
92 
93    /* Log this kernel call.  */
94     TX_EL_THREAD_IDENTIFY_INSERT
95 
96     /* Pickup thread pointer.  */
97     TX_THREAD_GET_CURRENT(thread_ptr)
98 
99     /* Restore interrupts.  */
100     TX_RESTORE
101 
102     /* Return the current thread pointer.  */
103     return(thread_ptr);
104 }
105 
106