1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** ThreadX Component                                                     */
16 /**                                                                       */
17 /**   Mutex                                                               */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define TX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "tx_api.h"
28 #include "tx_mutex.h"
29 
30 
31 #ifndef TX_INLINE_INITIALIZATION
32 
33 /* Locate mutex component data in this file.  */
34 
35 /* Define the head pointer of the created mutex list.  */
36 
37 TX_MUTEX *   _tx_mutex_created_ptr;
38 
39 
40 /* Define the variable that holds the number of created mutexes. */
41 
42 ULONG        _tx_mutex_created_count;
43 
44 
45 #ifdef TX_MUTEX_ENABLE_PERFORMANCE_INFO
46 
47 /* Define the total number of mutex puts.  */
48 
49 ULONG        _tx_mutex_performance_put_count;
50 
51 
52 /* Define the total number of mutex gets.  */
53 
54 ULONG        _tx_mutex_performance_get_count;
55 
56 
57 /* Define the total number of mutex suspensions.  */
58 
59 ULONG        _tx_mutex_performance_suspension_count;
60 
61 
62 /* Define the total number of mutex timeouts.  */
63 
64 ULONG        _tx_mutex_performance_timeout_count;
65 
66 
67 /* Define the total number of priority inversions.  */
68 
69 ULONG        _tx_mutex_performance_priority_inversion_count;
70 
71 
72 /* Define the total number of priority inheritance conditions.  */
73 
74 ULONG        _tx_mutex_performance__priority_inheritance_count;
75 
76 #endif
77 
78 
79 /**************************************************************************/
80 /*                                                                        */
81 /*  FUNCTION                                               RELEASE        */
82 /*                                                                        */
83 /*    _tx_mutex_initialize                                PORTABLE C      */
84 /*                                                           6.1          */
85 /*  AUTHOR                                                                */
86 /*                                                                        */
87 /*    William E. Lamie, Microsoft Corporation                             */
88 /*                                                                        */
89 /*  DESCRIPTION                                                           */
90 /*                                                                        */
91 /*    This function initializes the various control data structures for   */
92 /*    the mutex component.                                                */
93 /*                                                                        */
94 /*  INPUT                                                                 */
95 /*                                                                        */
96 /*    None                                                                */
97 /*                                                                        */
98 /*  OUTPUT                                                                */
99 /*                                                                        */
100 /*    None                                                                */
101 /*                                                                        */
102 /*  CALLS                                                                 */
103 /*                                                                        */
104 /*    None                                                                */
105 /*                                                                        */
106 /*  CALLED BY                                                             */
107 /*                                                                        */
108 /*    _tx_initialize_high_level         High level initialization         */
109 /*                                                                        */
110 /*  RELEASE HISTORY                                                       */
111 /*                                                                        */
112 /*    DATE              NAME                      DESCRIPTION             */
113 /*                                                                        */
114 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
115 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
116 /*                                            opt out of function when    */
117 /*                                            TX_INLINE_INITIALIZATION is */
118 /*                                            defined,                    */
119 /*                                            resulting in version 6.1    */
120 /*                                                                        */
121 /**************************************************************************/
_tx_mutex_initialize(VOID)122 VOID  _tx_mutex_initialize(VOID)
123 {
124 
125 #ifndef TX_DISABLE_REDUNDANT_CLEARING
126 
127     /* Initialize the head pointer of the created mutexes list and the
128        number of mutexes created.  */
129     _tx_mutex_created_ptr =        TX_NULL;
130     _tx_mutex_created_count =      TX_EMPTY;
131 
132 #ifdef TX_MUTEX_ENABLE_PERFORMANCE_INFO
133 
134     /* Initialize the mutex performance counters.  */
135     _tx_mutex_performance_put_count =                   ((ULONG) 0);
136     _tx_mutex_performance_get_count =                   ((ULONG) 0);
137     _tx_mutex_performance_suspension_count =            ((ULONG) 0);
138     _tx_mutex_performance_timeout_count =               ((ULONG) 0);
139     _tx_mutex_performance_priority_inversion_count =    ((ULONG) 0);
140     _tx_mutex_performance__priority_inheritance_count =  ((ULONG) 0);
141 #endif
142 #endif
143 }
144 #endif
145