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
105
106
107
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
138
139
140
141
142
143
144
145
146
147
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
185
186
187
188
189
190
191
192
198
199
200
201
202
203
204
205
206
207
208
209
210
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
249
250
256
257
258
259
260
261
263
264
265
266
267
268
280
281
282
283
284
285
291
292
293
294
300
301
302
303
304
305
306
312
313
314
316
317
318
319
320
321
322
323
325
326
327
333
334
335
337
338
342
343
344
345
346
348
349
350
351
352
353
359
360
361
362
363
364
365
366
367
368
369
370
376
377
378
381
382
383
384
385
386
392
393
394
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
530
531
535
536
537
538
539
540
541
542
543
544
550
551
552
554
555
556
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
589
590
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
614
615
616
617
618
619
621
622
623
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
...
...
...
#define TX_SOURCE_CODE
#include "tx_api.h"
#include "tx_trace.h"
#include "tx_thread.h"
#include "tx_mutex.h"
...
...
UINT _tx_mutex_put(TX_MUTEX *mutex_ptr)
{
TX_INTERRUPT_SAVE_AREA
TX_THREAD *thread_ptr;
TX_THREAD *old_owner;
UINT old_priority;
UINT status;
TX_MUTEX *next_mutex;
TX_MUTEX *previous_mutex;
UINT owned_count;
UINT suspended_count;
TX_THREAD *current_thread;
TX_THREAD *next_thread;
TX_THREAD *previous_thread;
TX_THREAD *suspended_thread;
UINT inheritance_priority;
status = TX_NOT_DONE;
TX_DISABLE
#ifdef TX_MUTEX_ENABLE_PERFORMANCE_INFO
_tx_mutex_performance_put_count++;
mutex_ptr -> tx_mutex_performance_put_count++;/* ... */
#endif
TX_TRACE_IN_LINE_INSERT(TX_TRACE_MUTEX_PUT, mutex_ptr, TX_POINTER_TO_ULONG_CONVERT(mutex_ptr -> tx_mutex_owner), mutex_ptr -> tx_mutex_ownership_count, TX_POINTER_TO_ULONG_CONVERT(&old_priority), TX_TRACE_MUTEX_EVENTS)
TX_EL_MUTEX_PUT_INSERT
if (mutex_ptr -> tx_mutex_ownership_count != ((UINT) 0))
{
thread_ptr = mutex_ptr -> tx_mutex_owner;
TX_THREAD_GET_CURRENT(current_thread)
if (mutex_ptr -> tx_mutex_owner != current_thread)
{
/* ... */
if (_tx_thread_preempt_disable == ((UINT) 0))
{
TX_RESTORE
status = TX_NOT_OWNED;
}if (_tx_thread_preempt_disable == ((UINT) 0)) { ... }
}if (mutex_ptr -> tx_mutex_owner != current_thread) { ... }
if (status == TX_NOT_DONE)
{
mutex_ptr -> tx_mutex_ownership_count--;
if (mutex_ptr -> tx_mutex_ownership_count != ((UINT) 0))
{
TX_RESTORE
status = TX_SUCCESS;
}if (mutex_ptr -> tx_mutex_ownership_count != ((UINT) 0)) { ... }
else
{
if (thread_ptr == TX_NULL)
{
TX_RESTORE
status = TX_SUCCESS;
}if (thread_ptr == TX_NULL) { ... }
else
{
thread_ptr -> tx_thread_owned_mutex_count--;
if (thread_ptr -> tx_thread_owned_mutex_count == ((UINT) 0))
{
thread_ptr -> tx_thread_owned_mutex_list = TX_NULL;
}if (thread_ptr -> tx_thread_owned_mutex_count == ((UINT) 0)) { ... }
else
{
next_mutex = mutex_ptr -> tx_mutex_owned_next;
previous_mutex = mutex_ptr -> tx_mutex_owned_previous;
next_mutex -> tx_mutex_owned_previous = previous_mutex;
previous_mutex -> tx_mutex_owned_next = next_mutex;
if (thread_ptr -> tx_thread_owned_mutex_list == mutex_ptr)
{
thread_ptr -> tx_thread_owned_mutex_list = next_mutex;
}if (thread_ptr -> tx_thread_owned_mutex_list == mutex_ptr) { ... }
}else { ... }
if (mutex_ptr -> tx_mutex_suspension_list == TX_NULL)
{
if (mutex_ptr -> tx_mutex_inherit == TX_FALSE)
{
mutex_ptr -> tx_mutex_owner = TX_NULL;
TX_RESTORE
status = TX_SUCCESS;
}if (mutex_ptr -> tx_mutex_inherit == TX_FALSE) { ... }
}if (mutex_ptr -> tx_mutex_suspension_list == TX_NULL) { ... }
if (status == TX_NOT_DONE)
{
old_owner = TX_NULL;
old_priority = thread_ptr -> tx_thread_user_priority;
if (mutex_ptr -> tx_mutex_inherit == TX_TRUE)
{
#ifndef TX_NOT_INTERRUPTABLE
_tx_thread_preempt_disable++;
TX_RESTORE/* ... */
#endif
inheritance_priority = ((UINT) TX_MAX_PRIORITIES);
/* ... */
next_mutex = thread_ptr -> tx_thread_owned_mutex_list;
while (next_mutex != TX_NULL)
{
if (next_mutex -> tx_mutex_inherit == TX_TRUE)
{
/* ... */
if (next_mutex -> tx_mutex_highest_priority_waiting < inheritance_priority)
{
inheritance_priority = next_mutex -> tx_mutex_highest_priority_waiting;
}if (next_mutex -> tx_mutex_highest_priority_waiting < inheritance_priority) { ... }
}if (next_mutex -> tx_mutex_inherit == TX_TRUE) { ... }
next_mutex = next_mutex -> tx_mutex_owned_next;
if (next_mutex == thread_ptr -> tx_thread_owned_mutex_list)
{
next_mutex = TX_NULL;
}if (next_mutex == thread_ptr -> tx_thread_owned_mutex_list) { ... }
}while (next_mutex != TX_NULL) { ... }
#ifndef TX_NOT_INTERRUPTABLE
TX_DISABLE
_tx_thread_preempt_disable--;/* ... */
#endif
thread_ptr -> tx_thread_inherit_priority = inheritance_priority;
if (inheritance_priority < old_priority)
{
old_priority = inheritance_priority;
}if (inheritance_priority < old_priority) { ... }
}if (mutex_ptr -> tx_mutex_inherit == TX_TRUE) { ... }
/* ... */
if (mutex_ptr -> tx_mutex_suspended_count > ((UINT) 1))
{
if (mutex_ptr -> tx_mutex_inherit == TX_TRUE)
{
/* ... */
#ifndef TX_NOT_INTERRUPTABLE
_tx_thread_preempt_disable++;
TX_RESTORE/* ... */
#endif
/* ... */
#ifdef TX_MISRA_ENABLE
do
{
status = _tx_mutex_prioritize(mutex_ptr);
...} while (status != TX_SUCCESS);/* ... */
#else
_tx_mutex_prioritize(mutex_ptr);
#endif
/* ... */
TX_MUTEX_PUT_EXTENSION_1
#ifndef TX_NOT_INTERRUPTABLE
TX_DISABLE
_tx_thread_preempt_disable--;/* ... */
#endif
}if (mutex_ptr -> tx_mutex_inherit == TX_TRUE) { ... }
}if (mutex_ptr -> tx_mutex_suspended_count > ((UINT) 1)) { ... }
if (mutex_ptr -> tx_mutex_suspension_list == TX_NULL)
{
#ifndef TX_NOT_INTERRUPTABLE
_tx_thread_preempt_disable++;
TX_RESTORE/* ... */
#endif
/* ... */
mutex_ptr -> tx_mutex_highest_priority_waiting = (UINT) TX_MAX_PRIORITIES;
if ((mutex_ptr -> tx_mutex_owner) -> tx_thread_priority != old_priority)
{
_tx_mutex_priority_change(mutex_ptr -> tx_mutex_owner, old_priority);
}if ((mutex_ptr -> tx_mutex_owner) -> tx_thread_priority != old_priority) { ... }
#ifndef TX_NOT_INTERRUPTABLE
TX_DISABLE
_tx_thread_preempt_disable--;/* ... */
#endif
mutex_ptr -> tx_mutex_owner = TX_NULL;
TX_RESTORE
_tx_thread_system_preempt_check();
status = TX_SUCCESS;
}if (mutex_ptr -> tx_mutex_suspension_list == TX_NULL) { ... }
else
{
thread_ptr = mutex_ptr -> tx_mutex_suspension_list;
/* ... */
if (mutex_ptr -> tx_mutex_inherit == TX_TRUE)
{
old_owner = mutex_ptr -> tx_mutex_owner;
mutex_ptr -> tx_mutex_original_priority = thread_ptr -> tx_thread_priority;
mutex_ptr -> tx_mutex_highest_priority_waiting = (UINT) TX_MAX_PRIORITIES;
}if (mutex_ptr -> tx_mutex_inherit == TX_TRUE) { ... }
owned_count = thread_ptr -> tx_thread_owned_mutex_count;
if (owned_count == ((UINT) 0))
{
thread_ptr -> tx_thread_owned_mutex_list = mutex_ptr;
mutex_ptr -> tx_mutex_owned_next = mutex_ptr;
mutex_ptr -> tx_mutex_owned_previous = mutex_ptr;
}if (owned_count == ((UINT) 0)) { ... }
else
{
next_mutex = thread_ptr -> tx_thread_owned_mutex_list;
previous_mutex = next_mutex -> tx_mutex_owned_previous;
next_mutex -> tx_mutex_owned_previous = mutex_ptr;
previous_mutex -> tx_mutex_owned_next = mutex_ptr;
mutex_ptr -> tx_mutex_owned_previous = previous_mutex;
mutex_ptr -> tx_mutex_owned_next = next_mutex;
}else { ... }
thread_ptr -> tx_thread_owned_mutex_count = owned_count + ((UINT) 1);
mutex_ptr -> tx_mutex_ownership_count = (UINT) 1;
mutex_ptr -> tx_mutex_owner = thread_ptr;
mutex_ptr -> tx_mutex_suspended_count--;
suspended_count = mutex_ptr -> tx_mutex_suspended_count;
if (suspended_count == TX_NO_SUSPENSIONS)
{
mutex_ptr -> tx_mutex_suspension_list = TX_NULL;
}if (suspended_count == TX_NO_SUSPENSIONS) { ... }
else
{
next_thread = thread_ptr -> tx_thread_suspended_next;
mutex_ptr -> tx_mutex_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 { ... }
thread_ptr -> tx_thread_suspend_cleanup = TX_NULL;
thread_ptr -> tx_thread_suspend_status = TX_SUCCESS;
#ifdef TX_NOT_INTERRUPTABLE
if (mutex_ptr -> tx_mutex_inherit == TX_TRUE)
{
if (mutex_ptr -> tx_mutex_suspended_count != ((ULONG) 0))
{
if (mutex_ptr -> tx_mutex_suspended_count > ((ULONG) 1))
{
/* ... */
#ifdef TX_MISRA_ENABLE
do
{
status = _tx_mutex_prioritize(mutex_ptr);
...} while (status != TX_SUCCESS);/* ... */
#else
_tx_mutex_prioritize(mutex_ptr);
#endif
}if (mutex_ptr -> tx_mutex_suspended_count > ((ULONG) 1)) { ... }
suspended_thread = mutex_ptr -> tx_mutex_suspension_list;
if (suspended_thread != TX_NULL)
{
mutex_ptr -> tx_mutex_highest_priority_waiting = suspended_thread -> tx_thread_priority;
}if (suspended_thread != TX_NULL) { ... }
}if (mutex_ptr -> tx_mutex_suspended_count != ((ULONG) 0)) { ... }
/* ... */
if (old_owner -> tx_thread_priority != old_priority)
{
_tx_mutex_priority_change(old_owner, old_priority);
}if (old_owner -> tx_thread_priority != old_priority) { ... }
}if (mutex_ptr -> tx_mutex_inherit == TX_TRUE) { ... }
_tx_thread_system_ni_resume(thread_ptr);
TX_RESTORE/* ... */
#else
_tx_thread_preempt_disable++;
TX_RESTORE
if (mutex_ptr -> tx_mutex_inherit == TX_TRUE)
{
if (mutex_ptr -> tx_mutex_suspended_count != TX_NO_SUSPENSIONS)
{
/* ... */
#ifdef TX_MISRA_ENABLE
do
{
status = _tx_mutex_prioritize(mutex_ptr);
...} while (status != TX_SUCCESS);/* ... */
#else
_tx_mutex_prioritize(mutex_ptr);
#endif
TX_MUTEX_PUT_EXTENSION_2
TX_DISABLE
suspended_thread = mutex_ptr -> tx_mutex_suspension_list;
if (suspended_thread != TX_NULL)
{
mutex_ptr -> tx_mutex_highest_priority_waiting = suspended_thread -> tx_thread_priority;
}if (suspended_thread != TX_NULL) { ... }
TX_RESTORE
}if (mutex_ptr -> tx_mutex_suspended_count != TX_NO_SUSPENSIONS) { ... }
/* ... */
if (old_owner -> tx_thread_priority != old_priority)
{
_tx_mutex_priority_change(old_owner, old_priority);
}if (old_owner -> tx_thread_priority != old_priority) { ... }
}if (mutex_ptr -> tx_mutex_inherit == TX_TRUE) { ... }
_tx_thread_system_resume(thread_ptr);/* ... */
#endif
status = TX_SUCCESS;
}else { ... }
}if (status == TX_NOT_DONE) { ... }
}else { ... }
}else { ... }
}if (status == TX_NOT_DONE) { ... }
}if (mutex_ptr -> tx_mutex_ownership_count != ((UINT) 0)) { ... }
else
{
TX_RESTORE
status = TX_NOT_OWNED;
}else { ... }
return(status);
}{ ... }