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