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);
    }
示例#2
0
void releaseRange()
{
	LBIDRange r;
	r.start = 12345;
	r.size = 5;
	copylocks.lock(CopyLocks::WRITE);
	copylocks.releaseRange(r);

	r.start = 12350;
	copylocks.releaseRange(r);
	copylocks.release(CopyLocks::WRITE);


	cout << "OK\n";
}