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 #define TX_THREAD_SMP_SOURCE_CODE
25
26
27 /* Include necessary system files. */
28
29 #include "tx_api.h"
30 #include "tx_trace.h"
31 #include "tx_thread.h"
32 #include "tx_initialize.h"
33
34
35 /**************************************************************************/
36 /* */
37 /* FUNCTION RELEASE */
38 /* */
39 /* _tx_thread_resume PORTABLE SMP */
40 /* 6.1 */
41 /* AUTHOR */
42 /* */
43 /* William E. Lamie, Microsoft Corporation */
44 /* */
45 /* DESCRIPTION */
46 /* */
47 /* This function processes application resume thread services. Actual */
48 /* thread resumption is performed in the core service. */
49 /* */
50 /* INPUT */
51 /* */
52 /* thread_ptr Pointer to thread to resume */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* status Service return status */
57 /* */
58 /* CALLS */
59 /* */
60 /* _tx_thread_smp_rebalance_execute_list Rebalance the execution list */
61 /* _tx_thread_system_resume Resume thread */
62 /* _tx_thread_system_ni_resume Non-interruptable resume */
63 /* */
64 /* CALLED BY */
65 /* */
66 /* Application Code */
67 /* */
68 /* RELEASE HISTORY */
69 /* */
70 /* DATE NAME DESCRIPTION */
71 /* */
72 /* 09-30-2020 William E. Lamie Initial Version 6.1 */
73 /* */
74 /**************************************************************************/
_tx_thread_resume(TX_THREAD * thread_ptr)75 UINT _tx_thread_resume(TX_THREAD *thread_ptr)
76 {
77
78 TX_INTERRUPT_SAVE_AREA
79
80 UINT status;
81 UINT core_index;
82
83
84 /* Lockout interrupts while the thread is being resumed. */
85 TX_DISABLE
86
87 /* If trace is enabled, insert this event into the trace buffer. */
88 TX_TRACE_IN_LINE_INSERT(TX_TRACE_THREAD_RESUME_API, thread_ptr, thread_ptr -> tx_thread_state, TX_POINTER_TO_ULONG_CONVERT(&status), 0, TX_TRACE_THREAD_EVENTS)
89
90 /* Log this kernel call. */
91 TX_EL_THREAD_RESUME_INSERT
92
93 /* Determine if the thread is suspended or in the process of suspending.
94 If so, call the thread resume processing. */
95 if (thread_ptr -> tx_thread_state == TX_SUSPENDED)
96 {
97
98 #ifdef TX_NOT_INTERRUPTABLE
99
100 /* Resume the thread! */
101 _tx_thread_system_ni_resume(thread_ptr);
102
103 /* Restore interrupts. */
104 TX_RESTORE
105 #else
106
107 /* Temporarily disable preemption. */
108 _tx_thread_preempt_disable++;
109
110 /* Restore interrupts. */
111 TX_RESTORE
112
113 /* Call the actual resume service to resume the thread. */
114 _tx_thread_system_resume(thread_ptr);
115 #endif
116
117 /* Disable interrupts. */
118 TX_DISABLE
119
120 /* Determine if the thread's preemption-threshold needs to be restored. */
121 if (_tx_thread_smp_current_state_get() >= TX_INITIALIZE_IN_PROGRESS)
122 {
123
124 #ifndef TX_DISABLE_PREEMPTION_THRESHOLD
125
126 /* Clear the preemption bit maps, since nothing has yet run during initialization. */
127 TX_MEMSET(_tx_thread_preempted_maps, 0, sizeof(_tx_thread_preempted_maps));
128 #if TX_MAX_PRIORITIES > 32
129 _tx_thread_preempted_map_active = ((ULONG) 0);
130 #endif
131 #endif
132 _tx_thread_preemption__threshold_scheduled = TX_NULL;
133
134 #ifdef TX_THREAD_SMP_DEBUG_ENABLE
135
136 /* Debug entry. */
137 _tx_thread_smp_debug_entry_insert(14, 0, thread_ptr);
138 #endif
139
140 /* Get the core index. */
141 core_index = TX_SMP_CORE_ID;
142
143 /* Call the rebalance routine. This routine maps cores and ready threads. */
144 _tx_thread_smp_rebalance_execute_list(core_index);
145
146 #ifdef TX_THREAD_SMP_DEBUG_ENABLE
147
148 /* Debug entry. */
149 _tx_thread_smp_debug_entry_insert(15, 0, thread_ptr);
150 #endif
151 }
152
153 /* Setup successful return status. */
154 status = TX_SUCCESS;
155 }
156 else if (thread_ptr -> tx_thread_delayed_suspend != TX_FALSE)
157 {
158
159 /* Clear the delayed suspension. */
160 thread_ptr -> tx_thread_delayed_suspend = TX_FALSE;
161
162 /* Setup delayed suspend lifted return status. */
163 status = TX_SUSPEND_LIFTED;
164 }
165 else
166 {
167
168 /* Setup invalid resume return status. */
169 status = TX_RESUME_ERROR;
170 }
171
172 /* Restore interrupts. */
173 TX_RESTORE
174
175 /* Return completion status. */
176 return(status);
177 }
178
179