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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
139
140
141
142
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
186
187
188
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
250
251
252
253
254
255
256
258
259
260
261
267
268
269
270
271
272
273
274
275
276
277
278
279
281
282
283
284
285
286
287
288
289
290
291
292
293
294
296
297
298
299
305
306
307
308
309
310
311
312
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
397
398
399
400
401
402
403
404
405
407
408
409
410
411
412
416
417
418
419
420
421
422
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
...
...
...
#define TX_SOURCE_CODE
#include "tx_api.h"
#include "tx_trace.h"
#include "tx_thread.h"
#include "tx_queue.h"
...
...
UINT _tx_queue_receive(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG wait_option)
{
TX_INTERRUPT_SAVE_AREA
TX_THREAD *thread_ptr;
ULONG *source;
ULONG *destination;
UINT size;
UINT suspended_count;
TX_THREAD *next_thread;
TX_THREAD *previous_thread;
UINT status;
status = TX_SUCCESS;
TX_DISABLE
#ifdef TX_QUEUE_ENABLE_PERFORMANCE_INFO
_tx_queue_performance__messages_received_count++;
queue_ptr -> tx_queue_performance_messages_received_count++;
/* ... */
#endif
TX_TRACE_IN_LINE_INSERT(TX_TRACE_QUEUE_RECEIVE, queue_ptr, TX_POINTER_TO_ULONG_CONVERT(destination_ptr), wait_option, queue_ptr -> tx_queue_enqueued, TX_TRACE_QUEUE_EVENTS)
TX_EL_QUEUE_RECEIVE_INSERT
suspended_count = queue_ptr -> tx_queue_suspended_count;
if (queue_ptr -> tx_queue_enqueued != TX_NO_MESSAGES)
{
if (suspended_count == TX_NO_SUSPENSIONS)
{
source = queue_ptr -> tx_queue_read;
destination = TX_VOID_TO_ULONG_POINTER_CONVERT(destination_ptr);
size = queue_ptr -> tx_queue_message_size;
/* ... */
TX_QUEUE_MESSAGE_COPY(source, destination, size)
if (source == queue_ptr -> tx_queue_end)
{
source = queue_ptr -> tx_queue_start;
}if (source == queue_ptr -> tx_queue_end) { ... }
queue_ptr -> tx_queue_read = source;
queue_ptr -> tx_queue_available_storage++;
queue_ptr -> tx_queue_enqueued--;
TX_RESTORE
}if (suspended_count == TX_NO_SUSPENSIONS) { ... }
else
{
thread_ptr = queue_ptr -> tx_queue_suspension_list;
if (thread_ptr -> tx_thread_suspend_option == TX_TRUE)
{
source = TX_VOID_TO_ULONG_POINTER_CONVERT(thread_ptr -> tx_thread_additional_suspend_info);
destination = TX_VOID_TO_ULONG_POINTER_CONVERT(destination_ptr);
size = queue_ptr -> tx_queue_message_size;
/* ... */
TX_QUEUE_MESSAGE_COPY(source, destination, size)
/* ... */
suspended_count--;
if (suspended_count == TX_NO_SUSPENSIONS)
{
queue_ptr -> tx_queue_suspension_list = TX_NULL;
}if (suspended_count == TX_NO_SUSPENSIONS) { ... }
else
{
next_thread = thread_ptr -> tx_thread_suspended_next;
queue_ptr -> tx_queue_suspension_list = next_thread;
previous_thread = thread_ptr -> tx_thread_suspended_previous;
next_thread -> tx_thread_suspended_previous = previous_thread;
previous_thread -> tx_thread_suspended_next = next_thread;
}else { ... }
queue_ptr -> tx_queue_suspended_count = suspended_count;
thread_ptr -> tx_thread_suspend_cleanup = TX_NULL;
thread_ptr -> tx_thread_suspend_status = TX_SUCCESS;
#ifdef TX_NOT_INTERRUPTABLE
_tx_thread_system_ni_resume(thread_ptr);
TX_RESTORE/* ... */
#else
_tx_thread_preempt_disable++;
TX_RESTORE
_tx_thread_system_resume(thread_ptr);/* ... */
#endif
}if (thread_ptr -> tx_thread_suspend_option == TX_TRUE) { ... }
else
{
/* ... */
source = queue_ptr -> tx_queue_read;
destination = TX_VOID_TO_ULONG_POINTER_CONVERT(destination_ptr);
size = queue_ptr -> tx_queue_message_size;
/* ... */
TX_QUEUE_MESSAGE_COPY(source, destination, size)
if (source == queue_ptr -> tx_queue_end)
{
source = queue_ptr -> tx_queue_start;
}if (source == queue_ptr -> tx_queue_end) { ... }
queue_ptr -> tx_queue_read = source;
_tx_thread_preempt_disable++;
#ifdef TX_NOT_INTERRUPTABLE
TX_RESTORE
/* ... */
TX_DISABLE/* ... */
#endif
_tx_thread_preempt_disable--;
source = TX_VOID_TO_ULONG_POINTER_CONVERT(thread_ptr -> tx_thread_additional_suspend_info);
destination = queue_ptr -> tx_queue_write;
size = queue_ptr -> tx_queue_message_size;
/* ... */
TX_QUEUE_MESSAGE_COPY(source, destination, size)
if (destination == queue_ptr -> tx_queue_end)
{
destination = queue_ptr -> tx_queue_start;
}if (destination == queue_ptr -> tx_queue_end) { ... }
queue_ptr -> tx_queue_write = destination;
thread_ptr = queue_ptr -> tx_queue_suspension_list;
/* ... */
suspended_count--;
if (suspended_count == TX_NO_SUSPENSIONS)
{
queue_ptr -> tx_queue_suspension_list = TX_NULL;
}if (suspended_count == TX_NO_SUSPENSIONS) { ... }
else
{
next_thread = thread_ptr -> tx_thread_suspended_next;
queue_ptr -> tx_queue_suspension_list = next_thread;
previous_thread = thread_ptr -> tx_thread_suspended_previous;
next_thread -> tx_thread_suspended_previous = previous_thread;
previous_thread -> tx_thread_suspended_next = next_thread;
}else { ... }
queue_ptr -> tx_queue_suspended_count = suspended_count;
thread_ptr -> tx_thread_suspend_cleanup = TX_NULL;
thread_ptr -> tx_thread_suspend_status = TX_SUCCESS;
#ifdef TX_NOT_INTERRUPTABLE
_tx_thread_system_ni_resume(thread_ptr);
TX_RESTORE/* ... */
#else
_tx_thread_preempt_disable++;
TX_RESTORE
_tx_thread_system_resume(thread_ptr);/* ... */
#endif
}else { ... }
}else { ... }
}if (queue_ptr -> tx_queue_enqueued != TX_NO_MESSAGES) { ... }
else if (wait_option != TX_NO_WAIT)
{
if (_tx_thread_preempt_disable != ((UINT) 0))
{
TX_RESTORE
status = TX_QUEUE_EMPTY;
}if (_tx_thread_preempt_disable != ((UINT) 0)) { ... }
else
{
#ifdef TX_QUEUE_ENABLE_PERFORMANCE_INFO
_tx_queue_performance_empty_suspension_count++;
queue_ptr -> tx_queue_performance_empty_suspension_count++;/* ... */
#endif
TX_THREAD_GET_CURRENT(thread_ptr)
thread_ptr -> tx_thread_suspend_cleanup = &(_tx_queue_cleanup);
/* ... */
thread_ptr -> tx_thread_suspend_control_block = (VOID *) queue_ptr;
thread_ptr -> tx_thread_additional_suspend_info = (VOID *) destination_ptr;
thread_ptr -> tx_thread_suspend_option = TX_FALSE;
#ifndef TX_NOT_INTERRUPTABLE
/* ... */
thread_ptr -> tx_thread_suspension_sequence++;/* ... */
#endif
if (suspended_count == TX_NO_SUSPENSIONS)
{
/* ... */
queue_ptr -> tx_queue_suspension_list = thread_ptr;
thread_ptr -> tx_thread_suspended_next = thread_ptr;
thread_ptr -> tx_thread_suspended_previous = thread_ptr;
}if (suspended_count == TX_NO_SUSPENSIONS) { ... }
else
{
next_thread = queue_ptr -> tx_queue_suspension_list;
thread_ptr -> tx_thread_suspended_next = next_thread;
previous_thread = next_thread -> tx_thread_suspended_previous;
thread_ptr -> tx_thread_suspended_previous = previous_thread;
previous_thread -> tx_thread_suspended_next = thread_ptr;
next_thread -> tx_thread_suspended_previous = thread_ptr;
}else { ... }
queue_ptr -> tx_queue_suspended_count = suspended_count + ((UINT) 1);
thread_ptr -> tx_thread_state = TX_QUEUE_SUSP;
#ifdef TX_NOT_INTERRUPTABLE
_tx_thread_system_ni_suspend(thread_ptr, wait_option);
TX_RESTORE/* ... */
#else
thread_ptr -> tx_thread_suspending = TX_TRUE;
thread_ptr -> tx_thread_timer.tx_timer_internal_remaining_ticks = wait_option;
_tx_thread_preempt_disable++;
TX_RESTORE
_tx_thread_system_suspend(thread_ptr);/* ... */
#endif
status = thread_ptr -> tx_thread_suspend_status;
}else { ... }
}else if (wait_option != TX_NO_WAIT) { ... }
else
{
TX_RESTORE
status = TX_QUEUE_EMPTY;
}else { ... }
return(status);
}{ ... }