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 /**   Mutex                                                               */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define TX_SOURCE_CODE
24 
25 
26 /* Include necessary system files.  */
27 
28 #include "tx_api.h"
29 #include "tx_trace.h"
30 #include "tx_mutex.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _tx_mutex_info_get                                  PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    William E. Lamie, Microsoft Corporation                             */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function retrieves information from the specified mutex.       */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    mutex_ptr                         Pointer to mutex control block    */
50 /*    name                              Destination for the mutex name    */
51 /*    count                             Destination for the owner count   */
52 /*    owner                             Destination for the owner's       */
53 /*                                        thread control block pointer    */
54 /*    first_suspended                   Destination for pointer of first  */
55 /*                                        thread suspended on the mutex   */
56 /*    suspended_count                   Destination for suspended count   */
57 /*    next_mutex                        Destination for pointer to next   */
58 /*                                        mutex on the created list       */
59 /*                                                                        */
60 /*  OUTPUT                                                                */
61 /*                                                                        */
62 /*    status                            Completion status                 */
63 /*                                                                        */
64 /*  CALLS                                                                 */
65 /*                                                                        */
66 /*    None                                                                */
67 /*                                                                        */
68 /*  CALLED BY                                                             */
69 /*                                                                        */
70 /*    Application Code                                                    */
71 /*                                                                        */
72 /*  RELEASE HISTORY                                                       */
73 /*                                                                        */
74 /*    DATE              NAME                      DESCRIPTION             */
75 /*                                                                        */
76 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
77 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
78 /*                                            resulting in version 6.1    */
79 /*                                                                        */
80 /**************************************************************************/
_tx_mutex_info_get(TX_MUTEX * mutex_ptr,CHAR ** name,ULONG * count,TX_THREAD ** owner,TX_THREAD ** first_suspended,ULONG * suspended_count,TX_MUTEX ** next_mutex)81 UINT  _tx_mutex_info_get(TX_MUTEX *mutex_ptr, CHAR **name, ULONG *count, TX_THREAD **owner,
82                     TX_THREAD **first_suspended, ULONG *suspended_count,
83                     TX_MUTEX **next_mutex)
84 {
85 
86 TX_INTERRUPT_SAVE_AREA
87 
88 
89     /* Disable interrupts.  */
90     TX_DISABLE
91 
92     /* If trace is enabled, insert this event into the trace buffer.  */
93     TX_TRACE_IN_LINE_INSERT(TX_TRACE_MUTEX_INFO_GET, mutex_ptr, 0, 0, 0, TX_TRACE_MUTEX_EVENTS)
94 
95     /* Log this kernel call.  */
96     TX_EL_MUTEX_INFO_GET_INSERT
97 
98     /* Retrieve all the pertinent information and return it in the supplied
99        destinations.  */
100 
101     /* Retrieve the name of the mutex.  */
102     if (name != TX_NULL)
103     {
104 
105         *name =  mutex_ptr -> tx_mutex_name;
106     }
107 
108     /* Retrieve the current ownership count of the mutex.  */
109     if (count != TX_NULL)
110     {
111 
112         *count =  ((ULONG) mutex_ptr -> tx_mutex_ownership_count);
113     }
114 
115     /* Retrieve the current owner of the mutex.  */
116     if (owner != TX_NULL)
117     {
118 
119         *owner =  mutex_ptr -> tx_mutex_owner;
120     }
121 
122     /* Retrieve the first thread suspended on this mutex.  */
123     if (first_suspended != TX_NULL)
124     {
125 
126         *first_suspended =  mutex_ptr -> tx_mutex_suspension_list;
127     }
128 
129     /* Retrieve the number of threads suspended on this mutex.  */
130     if (suspended_count != TX_NULL)
131     {
132 
133         *suspended_count =  (ULONG) mutex_ptr -> tx_mutex_suspended_count;
134     }
135 
136     /* Retrieve the pointer to the next mutex created.  */
137     if (next_mutex != TX_NULL)
138     {
139 
140         *next_mutex =  mutex_ptr -> tx_mutex_created_next;
141     }
142 
143     /* Restore interrupts.  */
144     TX_RESTORE
145 
146     /* Return completion status.  */
147     return(TX_SUCCESS);
148 }
149 
150