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_trace.h"
30 #include "tx_thread.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _tx_thread_info_get                                 PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    William E. Lamie, Microsoft Corporation                             */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function retrieves information from the specified thread.      */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    thread_ptr                        Pointer to thread control block   */
50 /*    name                              Destination for the thread name   */
51 /*    state                             Destination for thread state      */
52 /*    run_count                         Destination for thread run count  */
53 /*    priority                          Destination for thread priority   */
54 /*    preemption_threshold              Destination for thread preemption-*/
55 /*                                        threshold                       */
56 /*    time_slice                        Destination for thread time-slice */
57 /*    next_thread                       Destination for next created      */
58 /*                                        thread                          */
59 /*    next_suspended_thread             Destination for next suspended    */
60 /*                                        thread                          */
61 /*                                                                        */
62 /*  OUTPUT                                                                */
63 /*                                                                        */
64 /*    status                            Completion status                 */
65 /*                                                                        */
66 /*  CALLS                                                                 */
67 /*                                                                        */
68 /*    None                                                                */
69 /*                                                                        */
70 /*  CALLED BY                                                             */
71 /*                                                                        */
72 /*    Application Code                                                    */
73 /*                                                                        */
74 /*  RELEASE HISTORY                                                       */
75 /*                                                                        */
76 /*    DATE              NAME                      DESCRIPTION             */
77 /*                                                                        */
78 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
79 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
80 /*                                            resulting in version 6.1    */
81 /*                                                                        */
82 /**************************************************************************/
_tx_thread_info_get(TX_THREAD * thread_ptr,CHAR ** name,UINT * state,ULONG * run_count,UINT * priority,UINT * preemption_threshold,ULONG * time_slice,TX_THREAD ** next_thread,TX_THREAD ** next_suspended_thread)83 UINT  _tx_thread_info_get(TX_THREAD *thread_ptr, CHAR **name, UINT *state, ULONG *run_count,
84                 UINT *priority, UINT *preemption_threshold, ULONG *time_slice,
85                 TX_THREAD **next_thread, TX_THREAD **next_suspended_thread)
86 {
87 
88 TX_INTERRUPT_SAVE_AREA
89 
90 
91     /* Disable interrupts.  */
92     TX_DISABLE
93 
94     /* If trace is enabled, insert this event into the trace buffer.  */
95     TX_TRACE_IN_LINE_INSERT(TX_TRACE_THREAD_INFO_GET, thread_ptr, thread_ptr -> tx_thread_state, 0, 0, TX_TRACE_THREAD_EVENTS)
96 
97     /* Log this kernel call.  */
98     TX_EL_THREAD_INFO_GET_INSERT
99 
100     /* Retrieve all the pertinent information and return it in the supplied
101        destinations.  */
102 
103     /* Retrieve the name of the thread.  */
104     if (name != TX_NULL)
105     {
106 
107         *name =  thread_ptr -> tx_thread_name;
108     }
109 
110     /* Pickup the thread's current state.  */
111     if (state != TX_NULL)
112     {
113 
114         *state =  thread_ptr -> tx_thread_state;
115     }
116 
117     /* Pickup the number of times the thread has been scheduled.  */
118     if (run_count != TX_NULL)
119     {
120 
121         *run_count =  thread_ptr -> tx_thread_run_count;
122     }
123 
124     /* Pickup the thread's priority.  */
125     if (priority != TX_NULL)
126     {
127 
128         *priority =  thread_ptr -> tx_thread_user_priority;
129     }
130 
131     /* Pickup the thread's preemption-threshold.  */
132     if (preemption_threshold != TX_NULL)
133     {
134 
135         *preemption_threshold =  thread_ptr -> tx_thread_user_preempt_threshold;
136     }
137 
138     /* Pickup the thread's current time-slice.  */
139     if (time_slice != TX_NULL)
140     {
141 
142         *time_slice =  thread_ptr -> tx_thread_time_slice;
143     }
144 
145     /* Pickup the next created thread.  */
146     if (next_thread != TX_NULL)
147     {
148 
149         *next_thread =  thread_ptr -> tx_thread_created_next;
150     }
151 
152     /* Pickup the next thread suspended.  */
153     if (next_suspended_thread != TX_NULL)
154     {
155 
156         *next_suspended_thread =  thread_ptr -> tx_thread_suspended_next;
157     }
158 
159     /* Restore interrupts.  */
160     TX_RESTORE
161 
162     /* Return completion status.  */
163     return(TX_SUCCESS);
164 }
165 
166