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 
24 /**************************************************************************/
25 /*                                                                        */
26 /*  COMPONENT DEFINITION                                   RELEASE        */
27 /*                                                                        */
28 /*    tx_mutex.h                                          PORTABLE C      */
29 /*                                                           6.1          */
30 /*  AUTHOR                                                                */
31 /*                                                                        */
32 /*    William E. Lamie, Microsoft Corporation                             */
33 /*                                                                        */
34 /*  DESCRIPTION                                                           */
35 /*                                                                        */
36 /*    This file defines the ThreadX mutex management component,           */
37 /*    including all data types and external references.  It is assumed    */
38 /*    that tx_api.h and tx_port.h have already been included.             */
39 /*                                                                        */
40 /*  RELEASE HISTORY                                                       */
41 /*                                                                        */
42 /*    DATE              NAME                      DESCRIPTION             */
43 /*                                                                        */
44 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
45 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
46 /*                                            resulting in version 6.1    */
47 /*                                                                        */
48 /**************************************************************************/
49 
50 #ifndef TX_MUTEX_H
51 #define TX_MUTEX_H
52 
53 
54 /* Define mutex control specific data definitions.  */
55 
56 #define TX_MUTEX_ID                             ((ULONG) 0x4D555445)
57 
58 
59 /* Determine if in-line component initialization is supported by the
60    caller.  */
61 
62 #ifdef TX_INVOKE_INLINE_INITIALIZATION
63 
64 /* Yes, in-line initialization is supported, remap the mutex initialization
65    function.  */
66 
67 #ifndef TX_MUTEX_ENABLE_PERFORMANCE_INFO
68 #define _tx_mutex_initialize() \
69                     _tx_mutex_created_ptr =                             TX_NULL;      \
70                     _tx_mutex_created_count =                           TX_EMPTY
71 #else
72 #define _tx_mutex_initialize() \
73                     _tx_mutex_created_ptr =                             TX_NULL;      \
74                     _tx_mutex_created_count =                           TX_EMPTY;     \
75                     _tx_mutex_performance_put_count =                   ((ULONG) 0);  \
76                     _tx_mutex_performance_get_count =                   ((ULONG) 0);  \
77                     _tx_mutex_performance_suspension_count =            ((ULONG) 0);  \
78                     _tx_mutex_performance_timeout_count =               ((ULONG) 0);  \
79                     _tx_mutex_performance_priority_inversion_count =    ((ULONG) 0);  \
80                     _tx_mutex_performance__priority_inheritance_count = ((ULONG) 0)
81 #endif
82 #define TX_MUTEX_INIT
83 #else
84 
85 /* No in-line initialization is supported, use standard function call.  */
86 VOID        _tx_mutex_initialize(VOID);
87 #endif
88 
89 
90 /* Define internal mutex management function prototypes.  */
91 
92 VOID        _tx_mutex_cleanup(TX_THREAD *thread_ptr, ULONG suspension_sequence);
93 VOID        _tx_mutex_thread_release(TX_THREAD *thread_ptr);
94 VOID        _tx_mutex_priority_change(TX_THREAD *thread_ptr, UINT new_priority);
95 
96 
97 /* Mutex management component data declarations follow.  */
98 
99 /* Determine if the initialization function of this component is including
100    this file.  If so, make the data definitions really happen.  Otherwise,
101    make them extern so other functions in the component can access them.  */
102 
103 #ifdef TX_MUTEX_INIT
104 #define MUTEX_DECLARE
105 #else
106 #define MUTEX_DECLARE extern
107 #endif
108 
109 
110 /* Define the head pointer of the created mutex list.  */
111 
112 MUTEX_DECLARE  TX_MUTEX *   _tx_mutex_created_ptr;
113 
114 
115 /* Define the variable that holds the number of created mutexes. */
116 
117 MUTEX_DECLARE  ULONG        _tx_mutex_created_count;
118 
119 
120 #ifdef TX_MUTEX_ENABLE_PERFORMANCE_INFO
121 
122 /* Define the total number of mutex puts.  */
123 
124 MUTEX_DECLARE  ULONG        _tx_mutex_performance_put_count;
125 
126 
127 /* Define the total number of mutex gets.  */
128 
129 MUTEX_DECLARE  ULONG        _tx_mutex_performance_get_count;
130 
131 
132 /* Define the total number of mutex suspensions.  */
133 
134 MUTEX_DECLARE  ULONG        _tx_mutex_performance_suspension_count;
135 
136 
137 /* Define the total number of mutex timeouts.  */
138 
139 MUTEX_DECLARE  ULONG        _tx_mutex_performance_timeout_count;
140 
141 
142 /* Define the total number of priority inversions.  */
143 
144 MUTEX_DECLARE  ULONG        _tx_mutex_performance_priority_inversion_count;
145 
146 
147 /* Define the total number of priority inheritance conditions.  */
148 
149 MUTEX_DECLARE  ULONG        _tx_mutex_performance__priority_inheritance_count;
150 
151 
152 #endif
153 
154 
155 /* Define default post mutex delete macro to whitespace, if it hasn't been defined previously (typically in tx_port.h).  */
156 
157 #ifndef TX_MUTEX_DELETE_PORT_COMPLETION
158 #define TX_MUTEX_DELETE_PORT_COMPLETION(m)
159 #endif
160 
161 
162 #endif
163