tx_mutex.h 6.3 KB

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