Commit 5db59889 authored by unknown's avatar unknown

ndb - wl#1497 LinearPool seize_index


storage/ndb/src/kernel/vm/LinearPool.hpp:
  wl#1497 LinearPool seize_index
storage/ndb/src/kernel/vm/testSuperPool.cpp:
  wl#1497 LinearPool seize_index
parent 081cc155
This diff is collapsed.
#if 0
make -f Makefile -f - testSuperPool <<'_eof_'
testSuperPool: testSuperPool.cpp libkernel.a
testSuperPool: testSuperPool.cpp libkernel.a LinearPool.hpp
$(CXXCOMPILE) -o $@ $@.cpp libkernel.a -L../../common/util/.libs -lgeneral
_eof_
exit $?
......@@ -57,6 +57,7 @@ random_coprime(Uint32 n)
{
Uint32 prime[] = { 101, 211, 307, 401, 503, 601, 701, 809, 907 };
Uint32 count = sizeof(prime) / sizeof(prime[0]);
assert(n != 0);
while (1) {
Uint32 i = urandom(count);
if (n % prime[i] != 0)
......@@ -208,7 +209,7 @@ lp_test(GroupPool& gp)
ndbout << "linear pool test" << endl;
Ptr<T> ptr;
Uint32 loop;
for (loop = 0; loop < 3 * loopcount; loop++) {
for (loop = 0; loop < loopcount; loop++) {
int count = 0;
while (1) {
bool ret = lp.seize(ptr);
......@@ -223,6 +224,7 @@ lp_test(GroupPool& gp)
assert(ptr.p == ptr2.p);
count++;
}
assert(count != 0);
ndbout << "seized " << count << endl;
switch (loop % 3) {
case 0:
......@@ -264,6 +266,47 @@ lp_test(GroupPool& gp)
}
break;
}
{ Uint32 cnt = lp.count(); assert(cnt == 0); }
// seize_index test
char *used = new char [10 * count];
memset(used, false, sizeof(used));
Uint32 i, ns = 0, nr = 0;
for (i = 0; i < count; i++) {
Uint32 index = urandom(10 * count);
if (used[index]) {
ptr.i = index;
lp.release(ptr);
lp.verify();
nr++;
} else {
int i = lp.seize_index(ptr, index);
assert(i >= 0);
lp.verify();
if (i == 0) // no space
continue;
assert(ptr.i == index);
Ptr<T> ptr2;
ptr2.i = ptr.i;
ptr2.p = 0;
lp.getPtr(ptr2);
assert(ptr.p == ptr2.p);
ns++;
}
used[index] = ! used[index];
}
ndbout << "random sparse seize " << ns << " release " << nr << endl;
nr = 0;
for (i = 0; i < 10 * count; i++) {
if (used[i]) {
ptr.i = i;
lp.release(ptr);
lp.verify();
used[i] = false;
nr++;
}
}
ndbout << "released " << nr << endl;
{ Uint32 cnt = lp.count(); assert(cnt == 0); }
}
}
......@@ -291,8 +334,10 @@ template static void sp_test<T5>(GroupPool& sp);
template static void lp_test<T3>(GroupPool& sp);
int
main()
main(int argc, char** argv)
{
if (argc > 1 && strncmp(argv[1], "-l", 2) == 0)
loopcount = atoi(argv[1] + 2);
HeapPool sp(pageSize, pageBits);
sp.setInitPages(7);
sp.setMaxPages(7);
......@@ -304,7 +349,7 @@ main()
ndbout << "rand " << s << endl;
int count;
count = 0;
while (++count <= 0) {
while (++count <= 0) { // change to 1 to find new bug
sp_test<T1>(gp);
sp_test<T2>(gp);
sp_test<T3>(gp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment