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