Skip to content

Commit a788994

Browse files
authored
Merge branch 'microsoft:main' into main
2 parents 8301eb4 + b8e28be commit a788994

File tree

2 files changed

+63
-32
lines changed

2 files changed

+63
-32
lines changed

src/snmalloc/mem/pool.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ namespace snmalloc
202202
else
203203
{
204204
last->next = pool.front;
205-
pool.back->next = capptr::Alloc<T>::unsafe_from(first);
206205
}
207206
pool.front = capptr::Alloc<T>::unsafe_from(first);
208207
});

src/test/func/pool/pool.cc

Lines changed: 63 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,14 @@ struct PoolLargeEntry : Pooled<PoolLargeEntry>
4242

4343
using PoolLarge = Pool<PoolLargeEntry>;
4444

45-
template<bool order>
46-
struct PoolSortEntry : Pooled<PoolSortEntry<order>>
45+
struct PoolSortEntry : Pooled<PoolSortEntry>
4746
{
4847
int field;
4948

5049
PoolSortEntry() : field(1){};
5150
};
5251

53-
template<bool order>
54-
using PoolSort = Pool<PoolSortEntry<order>>;
52+
using PoolSort = Pool<PoolSortEntry>;
5553

5654
void test_alloc()
5755
{
@@ -159,50 +157,86 @@ void test_large()
159157
* This test confirms that the pool is sorted consistently with
160158
* respect to the iterator after a call to sort.
161159
*/
162-
template<bool order>
163160
void test_sort()
164161
{
165-
auto position = [](PoolSortEntry<order>* ptr) {
162+
auto position = [](PoolSortEntry* ptr) {
166163
size_t i = 0;
167-
auto curr = PoolSort<order>::iterate();
164+
auto curr = PoolSort::iterate();
168165
while (ptr != curr)
169166
{
170-
curr = PoolSort<order>::iterate(curr);
167+
curr = PoolSort::iterate(curr);
171168
++i;
172169
}
173170
return i;
174171
};
175172

176173
// This test checks that `sort` puts the elements in the right order,
177174
// so it is the same as if they had been allocated in that order.
178-
auto a1 = PoolSort<order>::acquire();
179-
auto a2 = PoolSort<order>::acquire();
175+
auto a1 = PoolSort::acquire();
176+
auto a2 = PoolSort::acquire();
177+
auto a3 = PoolSort::acquire();
180178

181179
auto position1 = position(a1);
182180
auto position2 = position(a2);
181+
auto position3 = position(a3);
183182

184-
// Release in either order.
185-
if (order)
186-
{
187-
PoolSort<order>::release(a1);
188-
PoolSort<order>::release(a2);
189-
}
190-
else
183+
PoolSort::release(a1);
184+
PoolSort::release(a2);
185+
PoolSort::release(a3);
186+
PoolSort::sort();
187+
188+
// Repeat the test to ensure it re-establishes the order.
189+
for (size_t i = 0; i < 12; i++)
191190
{
192-
PoolSort<order>::release(a2);
193-
PoolSort<order>::release(a1);
194-
}
191+
auto b1 = PoolSort::acquire();
192+
auto b2 = PoolSort::acquire();
193+
auto b3 = PoolSort::acquire();
195194

196-
PoolSort<order>::sort();
195+
auto new_position1 = position(b1);
196+
auto new_position2 = position(b2);
197+
auto new_position3 = position(b3);
197198

198-
auto b1 = PoolSort<order>::acquire();
199-
auto b2 = PoolSort<order>::acquire();
199+
SNMALLOC_CHECK(new_position1 == position1);
200+
SNMALLOC_CHECK(new_position2 == position2);
201+
SNMALLOC_CHECK(new_position3 == position3);
200202

201-
SNMALLOC_CHECK(position1 == position(b1));
202-
SNMALLOC_CHECK(position2 == position(b2));
203+
// Release in either order.
204+
switch (i % 6)
205+
{
206+
case 0:
207+
PoolSort::release(b1);
208+
PoolSort::release(b2);
209+
PoolSort::release(b3);
210+
break;
211+
case 1:
212+
PoolSort::release(b1);
213+
PoolSort::release(b3);
214+
PoolSort::release(b2);
215+
break;
216+
case 2:
217+
PoolSort::release(b2);
218+
PoolSort::release(b1);
219+
PoolSort::release(b3);
220+
break;
221+
case 3:
222+
PoolSort::release(b2);
223+
PoolSort::release(b3);
224+
PoolSort::release(b1);
225+
break;
226+
case 4:
227+
PoolSort::release(b3);
228+
PoolSort::release(b1);
229+
PoolSort::release(b2);
230+
break;
231+
case 5:
232+
PoolSort::release(b3);
233+
PoolSort::release(b2);
234+
PoolSort::release(b1);
235+
break;
236+
}
203237

204-
PoolSort<order>::release(b1);
205-
PoolSort<order>::release(b2);
238+
PoolSort::sort();
239+
}
206240
}
207241

208242
int main(int argc, char** argv)
@@ -230,9 +264,7 @@ int main(int argc, char** argv)
230264
std::cout << "test_iterator passed" << std::endl;
231265
test_large();
232266
std::cout << "test_large passed" << std::endl;
233-
test_sort<false>();
234-
std::cout << "test_sort<false> passed" << std::endl;
235-
test_sort<true>();
236-
std::cout << "test_sort<true> passed" << std::endl;
267+
test_sort();
268+
std::cout << "test_sort passed" << std::endl;
237269
return 0;
238270
}

0 commit comments

Comments
 (0)