1
10
13
14
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
87
88
89
90
91
92
93
94
95
112
113
114
115
116
117
118
119
120
121
122
123
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
146
147
148
150
151
152
153
154
164
165
166
167
168
169
170
171
172
173
174
175
181
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
...
...
...
#define TX_SOURCE_CODE
#include "tx_api.h"
#include "tx_trace.h"
#include "tx_thread.h"
...
...
UINT _tx_thread_preemption_change(TX_THREAD *thread_ptr, UINT new_threshold, UINT *old_threshold)
{
TX_INTERRUPT_SAVE_AREA
#ifndef TX_DISABLE_PREEMPTION_THRESHOLD
ULONG priority_bit;
#if TX_MAX_PRIORITIES > 32
UINT map_index;
#endif/* ... */
#endif
UINT status;
status = TX_SUCCESS;
#ifdef TX_DISABLE_PREEMPTION_THRESHOLD
/* ... */
if (thread_ptr -> tx_thread_user_priority != new_threshold)
{
if (new_threshold != ((UINT) 0))
{
/* ... */
new_threshold = ((UINT) 0);
}if (new_threshold != ((UINT) 0)) { ... }
}if (thread_ptr -> tx_thread_user_priority != new_threshold) { ... }
/* ... */#endif
TX_DISABLE
TX_TRACE_IN_LINE_INSERT(TX_TRACE_THREAD_PREEMPTION_CHANGE, thread_ptr, new_threshold, thread_ptr -> tx_thread_preempt_threshold, thread_ptr -> tx_thread_state, TX_TRACE_THREAD_EVENTS)
TX_EL_THREAD_PREEMPTION_CHANGE_INSERT
if (new_threshold > thread_ptr -> tx_thread_user_priority)
{
status = TX_THRESH_ERROR;
}if (new_threshold > thread_ptr -> tx_thread_user_priority) { ... }
else
{
#ifndef TX_DISABLE_PREEMPTION_THRESHOLD
if (thread_ptr -> tx_thread_user_priority == new_threshold)
{
if (_tx_thread_priority_list[thread_ptr -> tx_thread_priority] == thread_ptr)
{
#if TX_MAX_PRIORITIES > 32
map_index = (thread_ptr -> tx_thread_priority)/((UINT) 32);/* ... */
#endif
/* ... */
TX_MOD32_BIT_SET(thread_ptr -> tx_thread_priority, priority_bit)
_tx_thread_preempted_maps[MAP_INDEX] = _tx_thread_preempted_maps[MAP_INDEX] & (~(priority_bit));
#if TX_MAX_PRIORITIES > 32
if (_tx_thread_preempted_maps[MAP_INDEX] == ((ULONG) 0))
{
TX_DIV32_BIT_SET(thread_ptr -> tx_thread_priority, priority_bit)
_tx_thread_preempted_map_active = _tx_thread_preempted_map_active & (~(priority_bit));
}if (_tx_thread_preempted_maps[MAP_INDEX] == ((ULONG) 0)) { ... }
/* ... */#endif
}if (_tx_thread_priority_list[thread_ptr -> tx_thread_priority] == thread_ptr) { ... }
}if (thread_ptr -> tx_thread_user_priority == new_threshold) { ... }
/* ... */#endif
*old_threshold = thread_ptr -> tx_thread_user_preempt_threshold;
thread_ptr -> tx_thread_user_preempt_threshold = new_threshold;
if (new_threshold < thread_ptr -> tx_thread_inherit_priority)
{
thread_ptr -> tx_thread_preempt_threshold = new_threshold;
}if (new_threshold < thread_ptr -> tx_thread_inherit_priority) { ... }
else
{
thread_ptr -> tx_thread_preempt_threshold = thread_ptr -> tx_thread_inherit_priority;
}else { ... }
if (_tx_thread_highest_priority < thread_ptr -> tx_thread_priority)
{
if (_tx_thread_highest_priority < new_threshold)
{
if (_tx_thread_execute_ptr == thread_ptr)
{
#ifndef TX_DISABLE_PREEMPTION_THRESHOLD
if (thread_ptr -> tx_thread_preempt_threshold != thread_ptr -> tx_thread_priority)
{
#if TX_MAX_PRIORITIES > 32
map_index = (thread_ptr -> tx_thread_priority)/((UINT) 32);
TX_DIV32_BIT_SET(thread_ptr -> tx_thread_priority, priority_bit)
_tx_thread_preempted_map_active = _tx_thread_preempted_map_active | priority_bit;/* ... */
#endif
TX_MOD32_BIT_SET(thread_ptr -> tx_thread_priority, priority_bit)
_tx_thread_preempted_maps[MAP_INDEX] = _tx_thread_preempted_maps[MAP_INDEX] | priority_bit;
}if (thread_ptr -> tx_thread_preempt_threshold != thread_ptr -> tx_thread_priority) { ... }
/* ... */#endif
#ifdef TX_THREAD_ENABLE_PERFORMANCE_INFO
if (TX_THREAD_GET_SYSTEM_STATE() == ((ULONG) 0))
{
_tx_thread_performance_solicited_preemption_count++;
thread_ptr -> tx_thread_performance_solicited_preemption_count++;
}if (TX_THREAD_GET_SYSTEM_STATE() == ((ULONG) 0)) { ... }
thread_ptr -> tx_thread_performance_last_preempting_thread = _tx_thread_priority_list[_tx_thread_highest_priority];
if (_tx_thread_performance_execute_log[_tx_thread_performance__execute_log_index] != _tx_thread_execute_ptr)
{
_tx_thread_performance__execute_log_index++;
if (_tx_thread_performance__execute_log_index >= TX_THREAD_EXECUTE_LOG_SIZE)
{
_tx_thread_performance__execute_log_index = ((UINT) 0);
}if (_tx_thread_performance__execute_log_index >= TX_THREAD_EXECUTE_LOG_SIZE) { ... }
_tx_thread_performance_execute_log[_tx_thread_performance__execute_log_index] = _tx_thread_execute_ptr;
}if (_tx_thread_performance_execute_log[_tx_thread_performance__execute_log_index] != _tx_thread_execute_ptr) { ... }
/* ... */#endif
_tx_thread_execute_ptr = _tx_thread_priority_list[_tx_thread_highest_priority];
TX_RESTORE
_tx_thread_system_preempt_check();
TX_DISABLE
}if (_tx_thread_execute_ptr == thread_ptr) { ... }
}if (_tx_thread_highest_priority < new_threshold) { ... }
}if (_tx_thread_highest_priority < thread_ptr -> tx_thread_priority) { ... }
}else { ... }
TX_RESTORE
return(status);
}{ ... }