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