1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | //--------------------------------------------------------------------------- |
5 | // CCacheLineAllocator |
6 | // |
7 | |
8 | // |
9 | // @doc |
10 | // @module cachelineAlloc.h |
11 | // |
12 | // This file defines the CacheLine Allocator class. |
13 | // |
14 | // @comm |
15 | // |
16 | // |
17 | // <nl> Definitions.: |
18 | // <nl> Class Name Header file |
19 | // <nl> --------------------------- --------------- |
20 | // <nl> <c CCacheLineAllocator> BAlloc.h |
21 | // |
22 | // <nl><nl> |
23 | // Notes: |
24 | // The CacheLineAllocator maintains a pool of free CacheLines |
25 | // |
26 | // The CacheLine Allocator provides static member functions |
27 | // GetCacheLine and FreeCacheLine, |
28 | // |
29 | // <nl><nl> |
30 | // |
31 | //--------------------------------------------------------------------------- |
32 | |
33 | #ifndef _H_CACHELINE_ALLOCATOR_ |
34 | #define _H_CACHELINE_ALLOCATOR_ |
35 | |
36 | #include "slist.h" |
37 | |
38 | #include <pshpack1.h> |
39 | |
40 | class CacheLine |
41 | { |
42 | public: |
43 | enum |
44 | { |
45 | numEntries = 15, |
46 | numValidBytes = numEntries * sizeof(void *) |
47 | }; |
48 | |
49 | // store next pointer and the entries |
50 | SLink m_Link; |
51 | union |
52 | { |
53 | void* m_pAddr[numEntries]; |
54 | BYTE m_xxx[numValidBytes]; |
55 | }; |
56 | |
57 | // init |
58 | void Init32() |
59 | { |
60 | CONTRACTL |
61 | { |
62 | NOTHROW; |
63 | GC_NOTRIGGER; |
64 | MODE_ANY; |
65 | } |
66 | CONTRACTL_END; |
67 | |
68 | // initialize cacheline |
69 | memset(&m_Link,0,32); |
70 | } |
71 | |
72 | void Init64() |
73 | { |
74 | CONTRACTL |
75 | { |
76 | NOTHROW; |
77 | GC_NOTRIGGER; |
78 | MODE_ANY; |
79 | } |
80 | CONTRACTL_END; |
81 | |
82 | // initialize cacheline |
83 | memset(&m_Link,0,64); |
84 | } |
85 | |
86 | CacheLine() |
87 | { |
88 | CONTRACTL |
89 | { |
90 | NOTHROW; |
91 | GC_NOTRIGGER; |
92 | MODE_ANY; |
93 | } |
94 | CONTRACTL_END; |
95 | |
96 | // initialize cacheline |
97 | memset(&m_Link,0,sizeof(CacheLine)); |
98 | } |
99 | }; |
100 | #include <poppack.h> |
101 | |
102 | typedef CacheLine* LPCacheLine; |
103 | |
104 | ///////////////////////////////////////////////////////// |
105 | // class CCacheLineAllocator |
106 | // Handles Allocation/DeAllocation of cache lines |
107 | // used for hash table overflow buckets |
108 | /////////////////////////////////////////////////////// |
109 | class CCacheLineAllocator |
110 | { |
111 | typedef SList<CacheLine, true> REGISTRYLIST; |
112 | typedef SList<CacheLine, true> FREELIST32; |
113 | typedef SList<CacheLine, true> FREELIST64; |
114 | |
115 | public: |
116 | |
117 | //constructor |
118 | CCacheLineAllocator (); |
119 | //destructor |
120 | ~CCacheLineAllocator (); |
121 | |
122 | // free cacheline blocks |
123 | FREELIST32 m_freeList32; //32 byte |
124 | FREELIST64 m_freeList64; //64 byte |
125 | |
126 | // registry for virtual free |
127 | REGISTRYLIST m_registryList; |
128 | |
129 | void *VAlloc(ULONG cbSize); |
130 | |
131 | void VFree(void* pv); |
132 | |
133 | // GetCacheLine, |
134 | void * GetCacheLine32(); |
135 | |
136 | // GetCacheLine, |
137 | void * GetCacheLine64(); |
138 | |
139 | // FreeCacheLine, |
140 | void FreeCacheLine32(void *pCacheLine); |
141 | |
142 | // FreeCacheLine, |
143 | void FreeCacheLine64(void *pCacheLine); |
144 | |
145 | }; |
146 | #endif |
147 | |