Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define TX_SOURCE_CODE
#include "tx_api.h"
#include "tx_trace.h"
#include "tx_thread.h"
#include "tx_mutex.h"
...
...
_tx_mutex_put(TX_MUTEX *)
Files
loading (2/4)...
SourceVuSTM32 Libraries and Samplesthreadxcommon/src/tx_mutex_put.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
108
109
110
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
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
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
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
351
352
353
354
355
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** ThreadX Component */ /** */ /** Mutex */ /** */... /**************************************************************************/ /**************************************************************************/ #define TX_SOURCE_CODE /* Include necessary system files. */ #include "tx_api.h" #include "tx_trace.h" #include "tx_thread.h" #include "tx_mutex.h" ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _tx_mutex_put PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function puts back an instance of the specified mutex. */ /* */ /* INPUT */ /* */ /* mutex_ptr Pointer to mutex control block */ /* */ /* OUTPUT */ /* */ /* TX_SUCCESS Success completion status */ /* */ /* CALLS */ /* */ /* _tx_thread_system_preempt_check Check for preemption */ /* _tx_thread_system_resume Resume thread service */ /* _tx_thread_system_ni_resume Non-interruptable resume thread */ /* _tx_mutex_priority_change Restore previous thread priority */ /* _tx_mutex_prioritize Prioritize the mutex suspension */ /* _tx_mutex_thread_release Release all thread's mutexes */ /* _tx_mutex_delete Release ownership upon mutex */ /* deletion */ /* */ /* CALLED BY */ /* */ /* Application Code */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ 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; /* Setup status to indicate the processing is not complete. */ status = TX_NOT_DONE; /* Disable interrupts to put an instance back to the mutex. */ TX_DISABLE #ifdef TX_MUTEX_ENABLE_PERFORMANCE_INFO /* Increment the total mutex put counter. */ _tx_mutex_performance_put_count++; /* Increment the number of attempts to put this mutex. */ mutex_ptr -> tx_mutex_performance_put_count++;/* ... */ #endif /* If trace is enabled, insert this event into the trace buffer. */ 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) /* Log this kernel call. */ TX_EL_MUTEX_PUT_INSERT /* Determine if this mutex is owned. */ if (mutex_ptr -> tx_mutex_ownership_count != ((UINT) 0)) { /* Pickup the owning thread pointer. */ thread_ptr = mutex_ptr -> tx_mutex_owner; /* Pickup thread pointer. */ TX_THREAD_GET_CURRENT(current_thread) /* Check to see if the mutex is owned by the calling thread. */ if (mutex_ptr -> tx_mutex_owner != current_thread) { /* Determine if the preempt disable flag is set, indicating that the caller is not the application but from ThreadX. In such cases, the thread mutex owner does not need to match. *//* ... */ if (_tx_thread_preempt_disable == ((UINT) 0)) { /* Invalid mutex release. */ /* Restore interrupts. */ TX_RESTORE /* Caller does not own the mutex. */ status = TX_NOT_OWNED; }if (_tx_thread_preempt_disable == ((UINT) 0)) { ... } }if (mutex_ptr -> tx_mutex_owner != current_thread) { ... } /* Determine if we should continue. */ if (status == TX_NOT_DONE) { /* Decrement the mutex ownership count. */ mutex_ptr -> tx_mutex_ownership_count--; /* Determine if the mutex is still owned by the current thread. */ if (mutex_ptr -> tx_mutex_ownership_count != ((UINT) 0)) { /* Restore interrupts. */ TX_RESTORE /* Mutex is still owned, just return successful status. */ status = TX_SUCCESS; }if (mutex_ptr -> tx_mutex_ownership_count != ((UINT) 0)) { ... } else { /* Check for a NULL thread pointer, which can only happen during initialization. */ if (thread_ptr == TX_NULL) { /* Restore interrupts. */ TX_RESTORE /* Mutex is now available, return successful status. */ status = TX_SUCCESS; }if (thread_ptr == TX_NULL) { ... } else { /* The mutex is now available. */ /* Remove this mutex from the owned mutex list. */ /* Decrement the ownership count. */ thread_ptr -> tx_thread_owned_mutex_count--; /* Determine if this mutex was the only one on the list. */ if (thread_ptr -> tx_thread_owned_mutex_count == ((UINT) 0)) { /* Yes, the list is empty. Simply set the head pointer to NULL. */ thread_ptr -> tx_thread_owned_mutex_list = TX_NULL; }if (thread_ptr -> tx_thread_owned_mutex_count == ((UINT) 0)) { ... } else { /* No, there are more mutexes on the list. */ /* Link-up the neighbors. */ 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; /* See if we have to update the created list head pointer. */ if (thread_ptr -> tx_thread_owned_mutex_list == mutex_ptr) { /* Yes, move the head pointer to the next link. */ thread_ptr -> tx_thread_owned_mutex_list = next_mutex; }if (thread_ptr -> tx_thread_owned_mutex_list == mutex_ptr) { ... } }else { ... } /* Determine if the simple, non-suspension, non-priority inheritance case is present. */ if (mutex_ptr -> tx_mutex_suspension_list == TX_NULL) { /* Is this a priority inheritance mutex? */ if (mutex_ptr -> tx_mutex_inherit == TX_FALSE) { /* Yes, we are done - set the mutex owner to NULL. */ mutex_ptr -> tx_mutex_owner = TX_NULL; /* Restore interrupts. */ TX_RESTORE /* Mutex is now available, return successful status. */ status = TX_SUCCESS; }if (mutex_ptr -> tx_mutex_inherit == TX_FALSE) { ... } }if (mutex_ptr -> tx_mutex_suspension_list == TX_NULL) { ... } /* Determine if the processing is complete. */ if (status == TX_NOT_DONE) { /* Initialize original owner and thread priority. */ old_owner = TX_NULL; old_priority = thread_ptr -> tx_thread_user_priority; /* Does this mutex support priority inheritance? */ if (mutex_ptr -> tx_mutex_inherit == TX_TRUE) { #ifndef TX_NOT_INTERRUPTABLE /* Temporarily disable preemption. */ _tx_thread_preempt_disable++; /* Restore interrupts. */ TX_RESTORE/* ... */ #endif /* Default the inheritance priority to disabled. */ inheritance_priority = ((UINT) TX_MAX_PRIORITIES); /* Search the owned mutexes for this thread to determine the highest priority for this former mutex owner to return to. *//* ... */ next_mutex = thread_ptr -> tx_thread_owned_mutex_list; while (next_mutex != TX_NULL) { /* Does this mutex support priority inheritance? */ if (next_mutex -> tx_mutex_inherit == TX_TRUE) { /* Determine if highest priority field of the mutex is higher than the priority to restore. *//* ... */ if (next_mutex -> tx_mutex_highest_priority_waiting < inheritance_priority) { /* Use this priority to return releasing thread to. */ 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) { ... } /* Move mutex pointer to the next mutex in the list. */ next_mutex = next_mutex -> tx_mutex_owned_next; /* Are we at the end of the list? */ if (next_mutex == thread_ptr -> tx_thread_owned_mutex_list) { /* Yes, set the next mutex to NULL. */ next_mutex = TX_NULL; }if (next_mutex == thread_ptr -> tx_thread_owned_mutex_list) { ... } }while (next_mutex != TX_NULL) { ... } #ifndef TX_NOT_INTERRUPTABLE /* Disable interrupts. */ TX_DISABLE /* Undo the temporarily preemption disable. */ _tx_thread_preempt_disable--;/* ... */ #endif /* Set the inherit priority to that of the highest priority thread waiting on the mutex. */ thread_ptr -> tx_thread_inherit_priority = inheritance_priority; /* Determine if the inheritance priority is less than the default old priority. */ if (inheritance_priority < old_priority) { /* Yes, update the old priority. */ old_priority = inheritance_priority; }if (inheritance_priority < old_priority) { ... } }if (mutex_ptr -> tx_mutex_inherit == TX_TRUE) { ... } /* Determine if priority inheritance is in effect and there are one or more threads suspended on the mutex. *//* ... */ if (mutex_ptr -> tx_mutex_suspended_count > ((UINT) 1)) { /* Is priority inheritance in effect? */ if (mutex_ptr -> tx_mutex_inherit == TX_TRUE) { /* Yes, this code is simply to ensure the highest priority thread is positioned at the front of the suspension list. *//* ... */ #ifndef TX_NOT_INTERRUPTABLE /* Temporarily disable preemption. */ _tx_thread_preempt_disable++; /* Restore interrupts. */ TX_RESTORE/* ... */ #endif /* Call the mutex prioritize processing to ensure the highest priority thread is resumed. *//* ... */ #ifdef TX_MISRA_ENABLE do { status = _tx_mutex_prioritize(mutex_ptr); ...} while (status != TX_SUCCESS);/* ... */ #else _tx_mutex_prioritize(mutex_ptr); #endif /* At this point, the highest priority thread is at the front of the suspension list. *//* ... */ /* Optional processing extension. */ TX_MUTEX_PUT_EXTENSION_1 #ifndef TX_NOT_INTERRUPTABLE /* Disable interrupts. */ TX_DISABLE /* Back off the preemption disable. */ _tx_thread_preempt_disable--;/* ... */ #endif }if (mutex_ptr -> tx_mutex_inherit == TX_TRUE) { ... } }if (mutex_ptr -> tx_mutex_suspended_count > ((UINT) 1)) { ... } /* Now determine if there are any threads still waiting on the mutex. */ if (mutex_ptr -> tx_mutex_suspension_list == TX_NULL) { /* No, there are no longer any threads waiting on the mutex. */ #ifndef TX_NOT_INTERRUPTABLE /* Temporarily disable preemption. */ _tx_thread_preempt_disable++; /* Restore interrupts. */ TX_RESTORE/* ... */ #endif /* Mutex is not owned, but it is possible that a thread that caused a priority inheritance to occur is no longer waiting on the mutex. *//* ... */ /* Setup the highest priority waiting thread. */ mutex_ptr -> tx_mutex_highest_priority_waiting = (UINT) TX_MAX_PRIORITIES; /* Determine if we need to restore priority. */ if ((mutex_ptr -> tx_mutex_owner) -> tx_thread_priority != old_priority) { /* Yes, restore the priority of thread. */ _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 /* Disable interrupts again. */ TX_DISABLE /* Back off the preemption disable. */ _tx_thread_preempt_disable--;/* ... */ #endif /* Set the mutex owner to NULL. */ mutex_ptr -> tx_mutex_owner = TX_NULL; /* Restore interrupts. */ TX_RESTORE /* Check for preemption. */ _tx_thread_system_preempt_check(); /* Set status to success. */ status = TX_SUCCESS; }if (mutex_ptr -> tx_mutex_suspension_list == TX_NULL) { ... } else { /* Pickup the thread at the front of the suspension list. */ thread_ptr = mutex_ptr -> tx_mutex_suspension_list; /* Save the previous ownership information, if inheritance is in effect. *//* ... */ if (mutex_ptr -> tx_mutex_inherit == TX_TRUE) { /* Remember the old mutex owner. */ old_owner = mutex_ptr -> tx_mutex_owner; /* Setup owner thread priority information. */ mutex_ptr -> tx_mutex_original_priority = thread_ptr -> tx_thread_priority; /* Setup the highest priority waiting thread. */ mutex_ptr -> tx_mutex_highest_priority_waiting = (UINT) TX_MAX_PRIORITIES; }if (mutex_ptr -> tx_mutex_inherit == TX_TRUE) { ... } /* Determine how many mutexes are owned by this thread. */ owned_count = thread_ptr -> tx_thread_owned_mutex_count; /* Determine if this thread owns any other mutexes that have priority inheritance. */ if (owned_count == ((UINT) 0)) { /* The owned mutex list is empty. Add mutex to empty list. */ 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 { /* Non-empty list. Link up the mutex. */ /* Pickup tail pointer. */ next_mutex = thread_ptr -> tx_thread_owned_mutex_list; previous_mutex = next_mutex -> tx_mutex_owned_previous; /* Place the owned mutex in the list. */ next_mutex -> tx_mutex_owned_previous = mutex_ptr; previous_mutex -> tx_mutex_owned_next = mutex_ptr; /* Setup this mutex's next and previous created links. */ mutex_ptr -> tx_mutex_owned_previous = previous_mutex; mutex_ptr -> tx_mutex_owned_next = next_mutex; }else { ... } /* Increment the number of mutexes owned counter. */ thread_ptr -> tx_thread_owned_mutex_count = owned_count + ((UINT) 1); /* Mark the Mutex as owned and fill in the corresponding information. */ mutex_ptr -> tx_mutex_ownership_count = (UINT) 1; mutex_ptr -> tx_mutex_owner = thread_ptr; /* Remove the suspended thread from the list. */ /* Decrement the suspension count. */ mutex_ptr -> tx_mutex_suspended_count--; /* Pickup the suspended count. */ suspended_count = mutex_ptr -> tx_mutex_suspended_count; /* See if this is the only suspended thread on the list. */ if (suspended_count == TX_NO_SUSPENSIONS) { /* Yes, the only suspended thread. */ /* Update the head pointer. */ mutex_ptr -> tx_mutex_suspension_list = TX_NULL; }if (suspended_count == TX_NO_SUSPENSIONS) { ... } else { /* At least one more thread is on the same expiration list. */ /* Update the list head pointer. */ next_thread = thread_ptr -> tx_thread_suspended_next; mutex_ptr -> tx_mutex_suspension_list = next_thread; /* Update the links of the adjacent threads. */ 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 { ... } /* Prepare for resumption of the first thread. */ /* Clear cleanup routine to avoid timeout. */ thread_ptr -> tx_thread_suspend_cleanup = TX_NULL; /* Put return status into the thread control block. */ thread_ptr -> tx_thread_suspend_status = TX_SUCCESS; #ifdef TX_NOT_INTERRUPTABLE /* Determine if priority inheritance is enabled for this mutex. */ if (mutex_ptr -> tx_mutex_inherit == TX_TRUE) { /* Yes, priority inheritance is requested. */ /* Determine if there are any more threads still suspended on the mutex. */ if (mutex_ptr -> tx_mutex_suspended_count != ((ULONG) 0)) { /* Determine if there are more than one thread suspended on the mutex. */ if (mutex_ptr -> tx_mutex_suspended_count > ((ULONG) 1)) { /* If so, prioritize the list so the highest priority thread is placed at the front of the suspension list. *//* ... */ #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)) { ... } /* Now, pickup the list head and set the priority. */ /* Determine if there still are threads suspended for this mutex. */ suspended_thread = mutex_ptr -> tx_mutex_suspension_list; if (suspended_thread != TX_NULL) { /* Setup the highest priority thread waiting on this mutex. */ 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)) { ... } /* Restore previous priority needs to be restored after priority inheritance. *//* ... */ /* Determine if we need to restore priority. */ if (old_owner -> tx_thread_priority != old_priority) { /* Restore priority of thread. */ _tx_mutex_priority_change(old_owner, old_priority); }if (old_owner -> tx_thread_priority != old_priority) { ... } }if (mutex_ptr -> tx_mutex_inherit == TX_TRUE) { ... } /* Resume the thread! */ _tx_thread_system_ni_resume(thread_ptr); /* Restore interrupts. */ TX_RESTORE/* ... */ #else /* Temporarily disable preemption. */ _tx_thread_preempt_disable++; /* Restore interrupts. */ TX_RESTORE /* Determine if priority inheritance is enabled for this mutex. */ if (mutex_ptr -> tx_mutex_inherit == TX_TRUE) { /* Yes, priority inheritance is requested. */ /* Determine if there are any more threads still suspended on the mutex. */ if (mutex_ptr -> tx_mutex_suspended_count != TX_NO_SUSPENSIONS) { /* Prioritize the list so the highest priority thread is placed at the front of the suspension list. *//* ... */ #ifdef TX_MISRA_ENABLE do { status = _tx_mutex_prioritize(mutex_ptr); ...} while (status != TX_SUCCESS);/* ... */ #else _tx_mutex_prioritize(mutex_ptr); #endif /* Now, pickup the list head and set the priority. */ /* Optional processing extension. */ TX_MUTEX_PUT_EXTENSION_2 /* Disable interrupts. */ TX_DISABLE /* Determine if there still are threads suspended for this mutex. */ suspended_thread = mutex_ptr -> tx_mutex_suspension_list; if (suspended_thread != TX_NULL) { /* Setup the highest priority thread waiting on this mutex. */ mutex_ptr -> tx_mutex_highest_priority_waiting = suspended_thread -> tx_thread_priority; }if (suspended_thread != TX_NULL) { ... } /* Restore interrupts. */ TX_RESTORE }if (mutex_ptr -> tx_mutex_suspended_count != TX_NO_SUSPENSIONS) { ... } /* Restore previous priority needs to be restored after priority inheritance. *//* ... */ /* Is the priority different? */ if (old_owner -> tx_thread_priority != old_priority) { /* Restore the priority of thread. */ _tx_mutex_priority_change(old_owner, old_priority); }if (old_owner -> tx_thread_priority != old_priority) { ... } }if (mutex_ptr -> tx_mutex_inherit == TX_TRUE) { ... } /* Resume thread. */ _tx_thread_system_resume(thread_ptr);/* ... */ #endif /* Return a successful status. */ 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 { /* Restore interrupts. */ TX_RESTORE /* Caller does not own the mutex. */ status = TX_NOT_OWNED; }else { ... } /* Return the completion status. */ return(status); }{ ... }
Details