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_mutex.h"
30 
31 
32 #ifndef TX_INLINE_INITIALIZATION
33 
34 /* Locate mutex component data in this file.  */
35 
36 /* Define the head pointer of the created mutex list.  */
37 
38 TX_MUTEX *   _tx_mutex_created_ptr;
39 
40 
41 /* Define the variable that holds the number of created mutexes. */
42 
43 ULONG        _tx_mutex_created_count;
44 
45 
46 #ifdef TX_MUTEX_ENABLE_PERFORMANCE_INFO
47 
48 /* Define the total number of mutex puts.  */
49 
50 ULONG        _tx_mutex_performance_put_count;
51 
52 
53 /* Define the total number of mutex gets.  */
54 
55 ULONG        _tx_mutex_performance_get_count;
56 
57 
58 /* Define the total number of mutex suspensions.  */
59 
60 ULONG        _tx_mutex_performance_suspension_count;
61 
62 
63 /* Define the total number of mutex timeouts.  */
64 
65 ULONG        _tx_mutex_performance_timeout_count;
66 
67 
68 /* Define the total number of priority inversions.  */
69 
70 ULONG        _tx_mutex_performance_priority_inversion_count;
71 
72 
73 /* Define the total number of priority inheritance conditions.  */
74 
75 ULONG        _tx_mutex_performance__priority_inheritance_count;
76 
77 #endif
78 
79 
80 /**************************************************************************/
81 /*                                                                        */
82 /*  FUNCTION                                               RELEASE        */
83 /*                                                                        */
84 /*    _tx_mutex_initialize                                PORTABLE C      */
85 /*                                                           6.1          */
86 /*  AUTHOR                                                                */
87 /*                                                                        */
88 /*    William E. Lamie, Microsoft Corporation                             */
89 /*                                                                        */
90 /*  DESCRIPTION                                                           */
91 /*                                                                        */
92 /*    This function initializes the various control data structures for   */
93 /*    the mutex component.                                                */
94 /*                                                                        */
95 /*  INPUT                                                                 */
96 /*                                                                        */
97 /*    None                                                                */
98 /*                                                                        */
99 /*  OUTPUT                                                                */
100 /*                                                                        */
101 /*    None                                                                */
102 /*                                                                        */
103 /*  CALLS                                                                 */
104 /*                                                                        */
105 /*    None                                                                */
106 /*                                                                        */
107 /*  CALLED BY                                                             */
108 /*                                                                        */
109 /*    _tx_initialize_high_level         High level initialization         */
110 /*                                                                        */
111 /*  RELEASE HISTORY                                                       */
112 /*                                                                        */
113 /*    DATE              NAME                      DESCRIPTION             */
114 /*                                                                        */
115 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
116 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
117 /*                                            opt out of function when    */
118 /*                                            TX_INLINE_INITIALIZATION is */
119 /*                                            defined,                    */
120 /*                                            resulting in version 6.1    */
121 /*                                                                        */
122 /**************************************************************************/
_tx_mutex_initialize(VOID)123 VOID  _tx_mutex_initialize(VOID)
124 {
125 
126 #ifndef TX_DISABLE_REDUNDANT_CLEARING
127 
128     /* Initialize the head pointer of the created mutexes list and the
129        number of mutexes created.  */
130     _tx_mutex_created_ptr =        TX_NULL;
131     _tx_mutex_created_count =      TX_EMPTY;
132 
133 #ifdef TX_MUTEX_ENABLE_PERFORMANCE_INFO
134 
135     /* Initialize the mutex performance counters.  */
136     _tx_mutex_performance_put_count =                   ((ULONG) 0);
137     _tx_mutex_performance_get_count =                   ((ULONG) 0);
138     _tx_mutex_performance_suspension_count =            ((ULONG) 0);
139     _tx_mutex_performance_timeout_count =               ((ULONG) 0);
140     _tx_mutex_performance_priority_inversion_count =    ((ULONG) 0);
141     _tx_mutex_performance__priority_inheritance_count =  ((ULONG) 0);
142 #endif
143 #endif
144 }
145 #endif
146