Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
5.3 KiB

  1. #ifndef _SMP_HEAP_HPP_
  2. #define _SMP_HEAP_HPP_
  3. // Ruler
  4. // 1 2 3 4 5 6 7 8
  5. //345678901234567890123456789012345678901234567890123456789012345678901234567890
  6. /********************************************************************/
  7. /* */
  8. /* The standard layout. */
  9. /* */
  10. /* The standard layout for 'hpp' files for this code is as */
  11. /* follows: */
  12. /* */
  13. /* 1. Include files. */
  14. /* 2. Constants exported from the class. */
  15. /* 3. Data structures exported from the class. */
  16. /* 4. Forward references to other data structures. */
  17. /* 5. Class specifications (including inline functions). */
  18. /* 6. Additional large inline functions. */
  19. /* */
  20. /* Any portion that is not required is simply omitted. */
  21. /* */
  22. /********************************************************************/
  23. #include "Rockall.hpp"
  24. /********************************************************************/
  25. /* */
  26. /* Class forward references. */
  27. /* */
  28. /* We need to refer to the following classes before they are */
  29. /* fully specified so here we list them as forward references. */
  30. /* */
  31. /********************************************************************/
  32. class LIST;
  33. class THREAD_LOCAL_STORE;
  34. struct CACHE_STACK;
  35. struct THREAD_CACHE;
  36. /********************************************************************/
  37. /* */
  38. /* A SMP heap. */
  39. /* */
  40. /* A SMP heap is optimized for SMP performance. Each thread */
  41. /* is given its own private cache of memory allocations which */
  42. /* it can access without claiming a lock. */
  43. /* */
  44. /********************************************************************/
  45. class ROCKALL_DLL_LINKAGE SMP_HEAP : public ROCKALL
  46. {
  47. //
  48. // Private data.
  49. //
  50. bool Active;
  51. int MaxCaches1;
  52. int MaxCaches2;
  53. int MaxSize1;
  54. int MaxSize2;
  55. int ShiftSize1;
  56. int ShiftSize2;
  57. LIST *ActiveList;
  58. LIST *FreeList;
  59. THREAD_LOCAL_STORE *Tls;
  60. public:
  61. //
  62. // Public functions.
  63. //
  64. SMP_HEAP
  65. (
  66. int MaxFreeSpace = 4194304,
  67. bool Recycle = true,
  68. bool SingleImage = false,
  69. bool ThreadSafe = true
  70. );
  71. //
  72. // Manipulate allocations.
  73. //
  74. // The first group of functions manipulate
  75. // single or small arrays of allocations.
  76. //
  77. virtual bool Delete
  78. (
  79. void *Address,
  80. int Size = NoSize
  81. );
  82. virtual void *New
  83. (
  84. int Size,
  85. int *Space = NULL,
  86. bool Zero = false
  87. );
  88. virtual bool Verify
  89. (
  90. void *Address = NULL,
  91. int *Space = NULL
  92. );
  93. //
  94. // Manipulate the heap.
  95. //
  96. // The second group of functions act upon a heap
  97. // as a whole.
  98. //
  99. virtual void DeleteAll( bool Recycle = true );
  100. virtual bool Truncate( int MaxFreeSpace = 0 );
  101. virtual bool Walk
  102. (
  103. bool *Active,
  104. void **Address,
  105. int *Space
  106. );
  107. ~SMP_HEAP( void );
  108. private:
  109. //
  110. // Private functions.
  111. //
  112. void CreateThreadCache( void );
  113. void ActivateCacheStack( CACHE_STACK *CacheStack );
  114. CACHE_STACK *FindCache
  115. (
  116. int Size,
  117. THREAD_CACHE *ThreadCache
  118. );
  119. void FlushAllThreadCaches( void );
  120. void FlushThreadCache( THREAD_CACHE *ThreadCache );
  121. void FlushCacheStack( CACHE_STACK *CacheStack );
  122. bool SearchAllThreadCaches
  123. (
  124. void *Address,
  125. int Size
  126. );
  127. bool SearchThreadCache
  128. (
  129. void *Address,
  130. int Size,
  131. THREAD_CACHE *ThreadCache
  132. );
  133. bool SearchCacheStack
  134. (
  135. void *Address,
  136. CACHE_STACK *CacheStack
  137. );
  138. void DeleteThreadCache( void );
  139. //
  140. // Disabled operations.
  141. //
  142. // All copy constructors and class assignment
  143. // operations are disabled.
  144. //
  145. SMP_HEAP( const SMP_HEAP & Copy );
  146. void operator=( const SMP_HEAP & Copy );
  147. };
  148. #endif