Skip to content

Commit

Permalink
refs #6449 hopefully fixed lock in the DiskBufferTest.h
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Apr 9, 2013
1 parent 5bfcbb9 commit 59de5b5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 257 deletions.
24 changes: 11 additions & 13 deletions Code/Mantid/Framework/Kernel/src/ISaveable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ namespace Mantid
namespace Kernel
{

/** Constructor
*/
/** Constructor */
ISaveable::ISaveable():
// m_FileId(0),
m_fileIndexStart(std::numeric_limits<uint64_t>::max() ),m_fileNumEvents(0),m_BufMemorySize(0)
{}

Expand All @@ -23,28 +21,28 @@ namespace Kernel
m_BufMemorySize(other.m_BufMemorySize)
{ }

//ISaveable::ISaveable(const size_t fileId):
// m_FileId(fileId),m_fileIndexStart(std::numeric_limits<uint64_t>::max() ),m_fileNumEvents(0),m_BufMemorySize(0)
//{}



/** Method stores the position of the object in Disc buffer and returns the size of this object for disk buffer to store
* @param bufPosition -- the allocator which specifies the position of the object in the list of objects to write
* @returns the size of the object it currently occupies in memory. This size is also stored by the object itself for further references
*/
size_t ISaveable::setBufferPosition(std::list<ISaveable *>::iterator bufPosition)
{
m_setter.lock();
Mutex::ScopedLock _lock(m_setter);

m_BufPosition = boost::optional<std::list<ISaveable *>::iterator >(bufPosition);
m_BufMemorySize = this->getDataMemorySize();
m_setter.unlock();

return m_BufMemorySize ;
}

/** private function which used by the disk buffer to save the contents of the */
void ISaveable::saveAt(uint64_t newPos, uint64_t newSize)
{
m_setter.lock();

Mutex::ScopedLock _lock(m_setter);

// load old contents if it was there
if(this->wasSaved())
this->load();
Expand All @@ -54,15 +52,15 @@ namespace Kernel
// save in the new location
this->save();
this->clearDataFromMemory();
m_setter.unlock();
}
/// clears the state of the object, and indicate that it is not stored in buffer any more
void ISaveable::clearBufferState()
{
m_setter.lock();
Mutex::ScopedLock _lock(m_setter);

m_BufMemorySize=0;
m_BufPosition = boost::optional<std::list<ISaveable *>::iterator>();
m_setter.unlock();

}
} // namespace Mantid
} // namespace Kernel
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/Kernel/src/Saveable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ namespace Mantid
*/
void Saveable::setFilePosition(uint64_t newPos, size_t newSize, bool wasSaved)
{
this->m_setter.lock();
Mutex::ScopedLock (this->m_setter);
this->m_fileIndexStart=newPos;
this->m_fileNumEvents =static_cast<uint64_t>(newSize);
m_wasSaved = wasSaved;
this->m_setter.unlock();

}


Expand Down
51 changes: 27 additions & 24 deletions Code/Mantid/Framework/Kernel/test/DiskBufferTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ class SaveableTesterWithFile : public Saveable
fakeFile[i] = m_ch;

streamMutex.unlock();
// this is important function call which has to be implemented by any save function
this->m_wasSaved=true;

(const_cast<SaveableTesterWithFile *>(this))->setFilePosition(mPos,mMem,true);

}

virtual void load()
Expand All @@ -109,6 +111,7 @@ class SaveableTesterWithFile : public Saveable
{
m_memory+=this->getFileSize();
}
// this is important function call which has to be implemented by any load function
this->setLoaded(true);
}
virtual void flushData() const {}
Expand Down Expand Up @@ -150,13 +153,13 @@ class DiskBufferTest : public CxxTest::TestSuite
data[i]= NULL;
}
}
void test_nothing()
void xest_nothing()
{
TS_WARN("Tests here were disabled for the time being");
}

/** Extreme case with nothing writable but exceeding the writable buffer */
void xest_noWriteBuffer_nothingWritable()
void test_noWriteBuffer_nothingWritable()
{
//Room for 4 in the write buffer
DiskBuffer dbuf(4);
Expand All @@ -183,7 +186,7 @@ class DiskBufferTest : public CxxTest::TestSuite
}

/** Extreme case with nothing writable but exceeding the writable buffer */
void xest_noWriteBuffer_nothingWritableWasSaved()
void test_noWriteBuffer_nothingWritableWasSaved()
{
//Room for 4 in the write buffer
DiskBuffer dbuf(4);
Expand All @@ -208,7 +211,7 @@ class DiskBufferTest : public CxxTest::TestSuite

////--------------------------------------------------------------------------------
///** Sorts by file position when writing to a file */
void xest_writesOutInFileOrder()
void test_writesOutInFileOrder()
{
for(size_t i=0;i<data.size();i++)
{
Expand Down Expand Up @@ -243,7 +246,7 @@ class DiskBufferTest : public CxxTest::TestSuite
//--------------------------------------------------------------------------------
/** If a block will get deleted it needs to be taken
* out of the caches */
void xest_objectDeleted()
void test_objectDeleted()
{
// Room for 6 objects of 2 in the to-write cache
DiskBuffer dbuf(12);
Expand Down Expand Up @@ -289,7 +292,7 @@ class DiskBufferTest : public CxxTest::TestSuite

//--------------------------------------------------------------------------------
/** Accessing the map from multiple threads simultaneously does not segfault */
void xest_thread_safety()
void test_thread_safety()
{
// Room for 3 in the to-write cache
DiskBuffer dbuf(3);
Expand All @@ -316,7 +319,7 @@ class DiskBufferTest : public CxxTest::TestSuite
////--------------------------------------------------------------------------------
////--------------------------------------------------------------------------------
/** Freeing blocks get merged properly */
void xest_freeBlock_mergesWithPrevious()
void test_freeBlock_mergesWithPrevious()
{
DiskBuffer dbuf(3);
DiskBuffer::freeSpace_t & map = dbuf.getFreeSpaceMap();
Expand Down Expand Up @@ -344,7 +347,7 @@ class DiskBufferTest : public CxxTest::TestSuite
}

/** Freeing blocks get merged properly */
void xest_freeBlock_mergesWithNext()
void test_freeBlock_mergesWithNext()
{
DiskBuffer dbuf(3);
DiskBuffer::freeSpace_t & map = dbuf.getFreeSpaceMap();
Expand All @@ -370,7 +373,7 @@ class DiskBufferTest : public CxxTest::TestSuite
}

/** Freeing blocks get merged properly */
void xest_freeBlock_mergesWithBothNeighbours()
void test_freeBlock_mergesWithBothNeighbours()
{
DiskBuffer dbuf(3);
DiskBuffer::freeSpace_t & map = dbuf.getFreeSpaceMap();
Expand All @@ -395,7 +398,7 @@ class DiskBufferTest : public CxxTest::TestSuite

/** Add blocks to the free block list in parallel threads,
* should not segfault or anything */
void xest_freeBlock_threadSafety()
void test_freeBlock_threadSafety()
{
DiskBuffer dbuf(0);
PRAGMA_OMP( parallel for)
Expand All @@ -409,7 +412,7 @@ class DiskBufferTest : public CxxTest::TestSuite


///** Disabled because it is not necessary to defrag since that happens on the fly */
//void xxest_defragFreeBlocks()
//void xtest_defragFreeBlocks()
//{
// DiskBuffer dbuf(3);
// DiskBuffer::freeSpace_t & map = dbuf.getFreeSpaceMap();
Expand All @@ -430,7 +433,7 @@ class DiskBufferTest : public CxxTest::TestSuite
//}

/// You can call relocate() if an block is shrinking.
void xest_relocate_when_shrinking()
void test_relocate_when_shrinking()
{
DiskBuffer dbuf(3);
DiskBuffer::freeSpace_t & map = dbuf.getFreeSpaceMap();
Expand All @@ -446,7 +449,7 @@ class DiskBufferTest : public CxxTest::TestSuite
}

/// You can call relocate() if an block is shrinking.
void xest_relocate_when_growing()
void test_relocate_when_growing()
{
DiskBuffer dbuf(3);
DiskBuffer::freeSpace_t & map = dbuf.getFreeSpaceMap();
Expand All @@ -466,7 +469,7 @@ class DiskBufferTest : public CxxTest::TestSuite


/// Various tests of allocating and relocating
void xest_allocate_from_empty_freeMap()
void test_allocate_from_empty_freeMap()
{
DiskBuffer dbuf(3);
dbuf.setFileLength(1000); // Lets say the file goes up to 1000
Expand All @@ -489,7 +492,7 @@ class DiskBufferTest : public CxxTest::TestSuite


/// Various tests of allocating and relocating
void xest_allocate_and_relocate()
void test_allocate_and_relocate()
{
DiskBuffer dbuf(3);
dbuf.setFileLength(1000); // Lets say the file goes up to 1000
Expand Down Expand Up @@ -527,7 +530,7 @@ class DiskBufferTest : public CxxTest::TestSuite
////--------------------------------------------------------------------------------
////--------------------------------------------------------------------------------

void xest_allocate_with_file_manually()
void test_allocate_with_file_manually()
{
// Start by faking a file
SaveableTesterWithFile * blockA = new SaveableTesterWithFile(0, 0, 2, 'A');
Expand Down Expand Up @@ -591,7 +594,7 @@ class DiskBufferTest : public CxxTest::TestSuite
//std::cout << SaveableTesterWithFile::fakeFile << "!" << std::endl;
}

void xest_allocate_with_file()
void test_allocate_with_file()
{
SaveableTesterWithFile::fakeFile ="";
// filePosition has to be identified by the fileBuffer
Expand Down Expand Up @@ -791,14 +794,14 @@ class DiskBufferTestPerformance : public CxxTest::TestSuite
SaveableTesterWithSeek::fakeFile = "";
}

void test_nothing()
void xest_nothing()
{
TS_WARN("Tests here were disabled for the time being");
}


/** Demonstrate that using a write buffer reduces time spent seeking on disk */
void xest_withFakeSeeking_withWriteBuffer()
void test_withFakeSeeking_withWriteBuffer()
{
CPUTimer tim;
DiskBuffer dbuf(10);
Expand All @@ -811,7 +814,7 @@ class DiskBufferTestPerformance : public CxxTest::TestSuite
}

/** Use a 0-sized write buffer so that it constantly needs to seek and write out. This should be slower due to seeking. */
void xest_withFakeSeeking_noWriteBuffer()
void test_withFakeSeeking_noWriteBuffer()
{
CPUTimer tim;
DiskBuffer dbuf(0);
Expand All @@ -825,7 +828,7 @@ class DiskBufferTestPerformance : public CxxTest::TestSuite

/** Example of a situation where vectors grew, meaning that they need to be
* relocated causing lots of seeking if no write buffer exists.*/
void xest_withFakeSeeking_growingData()
void test_withFakeSeeking_growingData()
{
CPUTimer tim;
DiskBuffer dbuf(20);
Expand All @@ -843,7 +846,7 @@ class DiskBufferTestPerformance : public CxxTest::TestSuite

/** Demonstrate that calling "save" manually without using the MRU write buffer will slow things down
* due to seeking. Was an issue in LoadMD */
void xest_withFakeSeeking_growingData_savingWithoutUsingMRU()
void test_withFakeSeeking_growingData_savingWithoutUsingMRU()
{
CPUTimer tim;
DiskBuffer dbuf(dataSeek.size());
Expand All @@ -857,7 +860,7 @@ class DiskBufferTestPerformance : public CxxTest::TestSuite
}

/** Speed of freeing a lot of blocks and putting them in the free space map */
void xest_freeBlock()
void test_freeBlock()
{
CPUTimer tim;
DiskBuffer dbuf(0);
Expand Down

0 comments on commit 59de5b5

Please sign in to comment.