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 /**   Semaphore                                                           */
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_semaphore.h"
30 #ifdef TX_SEMAPHORE_ENABLE_PERFORMANCE_INFO
31 #include "tx_trace.h"
32 #endif
33 
34 
35 /**************************************************************************/
36 /*                                                                        */
37 /*  FUNCTION                                               RELEASE        */
38 /*                                                                        */
39 /*    _tx_semaphore_performance_info_get                  PORTABLE C      */
40 /*                                                           6.1          */
41 /*  AUTHOR                                                                */
42 /*                                                                        */
43 /*    William E. Lamie, Microsoft Corporation                             */
44 /*                                                                        */
45 /*  DESCRIPTION                                                           */
46 /*                                                                        */
47 /*    This function retrieves performance information from the specified  */
48 /*    semaphore.                                                          */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    semaphore_ptr                     Pointer to semaphore control block*/
53 /*    puts                              Destination for the number of     */
54 /*                                        puts on to this semaphore       */
55 /*    gets                              Destination for the number of     */
56 /*                                        gets on this semaphore          */
57 /*    suspensions                       Destination for the number of     */
58 /*                                        suspensions on this semaphore   */
59 /*    timeouts                          Destination for number of timeouts*/
60 /*                                        on this semaphore               */
61 /*                                                                        */
62 /*  OUTPUT                                                                */
63 /*                                                                        */
64 /*    status                            Completion status                 */
65 /*                                                                        */
66 /*  CALLS                                                                 */
67 /*                                                                        */
68 /*    None                                                                */
69 /*                                                                        */
70 /*  CALLED BY                                                             */
71 /*                                                                        */
72 /*    Application Code                                                    */
73 /*                                                                        */
74 /*  RELEASE HISTORY                                                       */
75 /*                                                                        */
76 /*    DATE              NAME                      DESCRIPTION             */
77 /*                                                                        */
78 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
79 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
80 /*                                            resulting in version 6.1    */
81 /*                                                                        */
82 /**************************************************************************/
_tx_semaphore_performance_info_get(TX_SEMAPHORE * semaphore_ptr,ULONG * puts,ULONG * gets,ULONG * suspensions,ULONG * timeouts)83 UINT  _tx_semaphore_performance_info_get(TX_SEMAPHORE *semaphore_ptr, ULONG *puts, ULONG *gets,
84                     ULONG *suspensions, ULONG *timeouts)
85 {
86 
87 #ifdef TX_SEMAPHORE_ENABLE_PERFORMANCE_INFO
88 
89 TX_INTERRUPT_SAVE_AREA
90 UINT                    status;
91 
92 
93     /* Determine if this is a legal request.  */
94     if (semaphore_ptr == TX_NULL)
95     {
96 
97         /* Semaphore pointer is illegal, return error.  */
98         status =  TX_PTR_ERROR;
99     }
100 
101     /* Determine if the semaphore ID is invalid.  */
102     else if (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID)
103     {
104 
105         /* Semaphore pointer is illegal, return error.  */
106         status =  TX_PTR_ERROR;
107     }
108     else
109     {
110 
111         /* Disable interrupts.  */
112         TX_DISABLE
113 
114         /* If trace is enabled, insert this event into the trace buffer.  */
115         TX_TRACE_IN_LINE_INSERT(TX_TRACE_SEMAPHORE_PERFORMANCE_INFO_GET, semaphore_ptr, 0, 0, 0, TX_TRACE_SEMAPHORE_EVENTS)
116 
117         /* Log this kernel call.  */
118         TX_EL_SEMAPHORE_PERFORMANCE_INFO_GET_INSERT
119 
120         /* Retrieve all the pertinent information and return it in the supplied
121            destinations.  */
122 
123         /* Retrieve the number of puts on this semaphore.  */
124         if (puts != TX_NULL)
125         {
126 
127             *puts =  semaphore_ptr -> tx_semaphore_performance_put_count;
128         }
129 
130         /* Retrieve the number of gets on this semaphore.  */
131         if (gets != TX_NULL)
132         {
133 
134             *gets =  semaphore_ptr -> tx_semaphore_performance_get_count;
135         }
136 
137         /* Retrieve the number of suspensions on this semaphore.  */
138         if (suspensions != TX_NULL)
139         {
140 
141             *suspensions =  semaphore_ptr -> tx_semaphore_performance_suspension_count;
142         }
143 
144         /* Retrieve the number of timeouts on this semaphore.  */
145         if (timeouts != TX_NULL)
146         {
147 
148             *timeouts =  semaphore_ptr -> tx_semaphore_performance_timeout_count;
149         }
150 
151         /* Restore interrupts.  */
152         TX_RESTORE
153 
154         /* Return successful completion.  */
155         status =  TX_SUCCESS;
156     }
157 #else
158 UINT                    status;
159 
160 
161     /* Access input arguments just for the sake of lint, MISRA, etc.  */
162     if (semaphore_ptr != TX_NULL)
163     {
164 
165         /* Not enabled, return error.  */
166         status =  TX_FEATURE_NOT_ENABLED;
167     }
168     else if (puts != TX_NULL)
169     {
170 
171         /* Not enabled, return error.  */
172         status =  TX_FEATURE_NOT_ENABLED;
173     }
174     else if (gets != TX_NULL)
175     {
176 
177         /* Not enabled, return error.  */
178         status =  TX_FEATURE_NOT_ENABLED;
179     }
180     else if (suspensions != TX_NULL)
181     {
182 
183         /* Not enabled, return error.  */
184         status =  TX_FEATURE_NOT_ENABLED;
185     }
186     else if (timeouts != TX_NULL)
187     {
188 
189         /* Not enabled, return error.  */
190         status =  TX_FEATURE_NOT_ENABLED;
191     }
192     else
193     {
194 
195         /* Not enabled, return error.  */
196         status =  TX_FEATURE_NOT_ENABLED;
197     }
198 #endif
199 
200     /* Return completion status.  */
201     return(status);
202 }
203 
204