Refactor MultiDiskAdaptor::closeFile() and add assert for debugging

This commit is contained in:
Tatsuhiro Tsujikawa 2015-03-22 18:38:50 +09:00
parent b324be70ad
commit d03c7b32c6

View File

@ -141,6 +141,7 @@ std::unique_ptr<DiskWriterEntry> createDiskWriterEntry
void MultiDiskAdaptor::resetDiskWriterEntries()
{
assert(openedDiskWriterEntries_.empty());
diskWriterEntries_.clear();
if(getFileEntries().empty()) {
return;
@ -271,18 +272,19 @@ void MultiDiskAdaptor::openExistingFile()
void MultiDiskAdaptor::closeFile()
{
size_t n = 0;
openedDiskWriterEntries_.clear();
for(auto& dwent : diskWriterEntries_) {
if(dwent->isOpen()) {
++n;
dwent->closeFile();
for(auto& dwent : openedDiskWriterEntries_) {
auto& dw = dwent->getDiskWriter();
// required for unit test
if (!dw) {
continue;
}
dw->closeFile();
}
auto& openedFileCounter = getOpenedFileCounter();
if(openedFileCounter) {
openedFileCounter->reduceNumOfOpenedFile(n);
openedFileCounter->reduceNumOfOpenedFile(openedDiskWriterEntries_.size());
}
openedDiskWriterEntries_.clear();
}
namespace {