tx_byte_pool.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. /** Byte Memory */
  16. /** */
  17. /**************************************************************************/
  18. /**************************************************************************/
  19. /**************************************************************************/
  20. /* */
  21. /* COMPONENT DEFINITION RELEASE */
  22. /* */
  23. /* tx_byte_pool.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 byte memory 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_BYTE_POOL_H
  45. #define TX_BYTE_POOL_H
  46. /* Define byte memory control specific data definitions. */
  47. #define TX_BYTE_POOL_ID ((ULONG) 0x42595445)
  48. #ifndef TX_BYTE_BLOCK_FREE
  49. #define TX_BYTE_BLOCK_FREE ((ULONG) 0xFFFFEEEEUL)
  50. #endif
  51. #ifndef TX_BYTE_BLOCK_MIN
  52. #define TX_BYTE_BLOCK_MIN ((ULONG) 20)
  53. #endif
  54. #ifndef TX_BYTE_POOL_MIN
  55. #define TX_BYTE_POOL_MIN ((ULONG) 100)
  56. #endif
  57. /* Determine if in-line component initialization is supported by the
  58. caller. */
  59. #ifdef TX_INVOKE_INLINE_INITIALIZATION
  60. /* Yes, in-line initialization is supported, remap the byte memory pool
  61. initialization function. */
  62. #ifndef TX_BYTE_POOL_ENABLE_PERFORMANCE_INFO
  63. #define _tx_byte_pool_initialize() \
  64. _tx_byte_pool_created_ptr = TX_NULL; \
  65. _tx_byte_pool_created_count = TX_EMPTY
  66. #else
  67. #define _tx_byte_pool_initialize() \
  68. _tx_byte_pool_created_ptr = TX_NULL; \
  69. _tx_byte_pool_created_count = TX_EMPTY; \
  70. _tx_byte_pool_performance_allocate_count = ((ULONG) 0); \
  71. _tx_byte_pool_performance_release_count = ((ULONG) 0); \
  72. _tx_byte_pool_performance_merge_count = ((ULONG) 0); \
  73. _tx_byte_pool_performance_split_count = ((ULONG) 0); \
  74. _tx_byte_pool_performance_search_count = ((ULONG) 0); \
  75. _tx_byte_pool_performance_suspension_count = ((ULONG) 0); \
  76. _tx_byte_pool_performance_timeout_count = ((ULONG) 0)
  77. #endif
  78. #define TX_BYTE_POOL_INIT
  79. #else
  80. /* No in-line initialization is supported, use standard function call. */
  81. VOID _tx_byte_pool_initialize(VOID);
  82. #endif
  83. /* Define internal byte memory pool management function prototypes. */
  84. UCHAR *_tx_byte_pool_search(TX_BYTE_POOL *pool_ptr, ULONG memory_size);
  85. VOID _tx_byte_pool_cleanup(TX_THREAD *thread_ptr, ULONG suspension_sequence);
  86. /* Byte pool management component data declarations follow. */
  87. /* Determine if the initialization function of this component is including
  88. this file. If so, make the data definitions really happen. Otherwise,
  89. make them extern so other functions in the component can access them. */
  90. #ifdef TX_BYTE_POOL_INIT
  91. #define BYTE_POOL_DECLARE
  92. #else
  93. #define BYTE_POOL_DECLARE extern
  94. #endif
  95. /* Define the head pointer of the created byte pool list. */
  96. BYTE_POOL_DECLARE TX_BYTE_POOL * _tx_byte_pool_created_ptr;
  97. /* Define the variable that holds the number of created byte pools. */
  98. BYTE_POOL_DECLARE ULONG _tx_byte_pool_created_count;
  99. #ifdef TX_BYTE_POOL_ENABLE_PERFORMANCE_INFO
  100. /* Define the total number of allocates. */
  101. BYTE_POOL_DECLARE ULONG _tx_byte_pool_performance_allocate_count;
  102. /* Define the total number of releases. */
  103. BYTE_POOL_DECLARE ULONG _tx_byte_pool_performance_release_count;
  104. /* Define the total number of adjacent memory fragment merges. */
  105. BYTE_POOL_DECLARE ULONG _tx_byte_pool_performance_merge_count;
  106. /* Define the total number of memory fragment splits. */
  107. BYTE_POOL_DECLARE ULONG _tx_byte_pool_performance_split_count;
  108. /* Define the total number of memory fragments searched during allocation. */
  109. BYTE_POOL_DECLARE ULONG _tx_byte_pool_performance_search_count;
  110. /* Define the total number of byte pool suspensions. */
  111. BYTE_POOL_DECLARE ULONG _tx_byte_pool_performance_suspension_count;
  112. /* Define the total number of byte pool timeouts. */
  113. BYTE_POOL_DECLARE ULONG _tx_byte_pool_performance_timeout_count;
  114. #endif
  115. /* Define default post byte pool delete macro to whitespace, if it hasn't been defined previously (typically in tx_port.h). */
  116. #ifndef TX_BYTE_POOL_DELETE_PORT_COMPLETION
  117. #define TX_BYTE_POOL_DELETE_PORT_COMPLETION(p)
  118. #endif
  119. #endif