void lockRange() { LBIDRange r; r.start = 12345; r.size = 5; copylocks.lock(CopyLocks::WRITE); if (copylocks.isLocked(r)) cout << "already locked\n"; else { copylocks.lockRange(r, -1); cout << "got the 1st lock\n"; } r.start = 12349; if (copylocks.isLocked(r)) cout << "2nd range is locked\n"; else cout << "2nd range is NOT locked\n"; r.start = 12350; if (copylocks.isLocked(r)) cout << "3rd range is locked\n"; else { copylocks.lockRange(r, -1); cout << "got the 3rd lock\n"; } copylocks.release(CopyLocks::WRITE); }
void copyLocks_good_1() { CopyLocks cl; LBIDRange range; int i, iterations = 1000; cl.lock(CopyLocks::WRITE); range.start = 5; range.size = 2; cl.lockRange(range, 0); CPPUNIT_ASSERT(cl.isLocked(range) == true); range.start++; CPPUNIT_ASSERT(cl.isLocked(range) == true); range.start++; CPPUNIT_ASSERT(cl.isLocked(range) == false); range.start = 0; CPPUNIT_ASSERT(cl.isLocked(range) == false); range.start = 3; CPPUNIT_ASSERT(cl.isLocked(range) == false); range.start++; CPPUNIT_ASSERT(cl.isLocked(range) == true); range.start = 5; range.size = 1; CPPUNIT_ASSERT(cl.isLocked(range) == true); range.size = 2; cl.releaseRange(range); //make sure it can grow for (i = 0; i < iterations * 2; i += 2) { range.start = i; cl.lockRange(range, 0); } range.size = 1; for (i = 0; i < iterations * 2; i++) { range.start = i; CPPUNIT_ASSERT(cl.isLocked(range) == true); } range.start = i; CPPUNIT_ASSERT(cl.isLocked(range) == false); for (i = 0; i < iterations * 2; i += 2) { range.start = i; cl.releaseRange(range); } cl.release(CopyLocks::WRITE); }