Skip to content

Commit

Permalink
libdeng2|FileSystem: Use a read-write lock on the index
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed May 2, 2013
1 parent a91ca65 commit 1c8af51
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions doomsday/libdeng2/src/filesys/filesystem.cpp
Expand Up @@ -26,14 +26,14 @@
#include "de/PackageFolder"
#include "de/ZipArchive"
#include "de/Log"
#include "de/Lockable"
#include "de/ReadWriteLockable"
#include "de/Guard"

namespace de {

static FileSystem::Index const emptyIndex;

DENG2_PIMPL_NOREF(FileSystem), public Lockable
DENG2_PIMPL_NOREF(FileSystem), public ReadWriteLockable
{
/// The main index to all files in the file system.
FileSystem::Index index;
Expand Down Expand Up @@ -133,11 +133,12 @@ File *FileSystem::interpret(File *sourceData)
return sourceData;
}

#define DENG2_FS_GUARD_INDEX() DENG2_GUARD_FOR(*d, indexAccessGuard)
#define DENG2_FS_GUARD_INDEX_R() DENG2_GUARD_READ_FOR(*d, indexAccessGuardRead)
#define DENG2_FS_GUARD_INDEX_W() DENG2_GUARD_WRITE_FOR(*d, indexAccessGuardWrite)

FileSystem::Index const &FileSystem::nameIndex() const
{
DENG2_FS_GUARD_INDEX();
DENG2_FS_GUARD_INDEX_R();

return d->index;
}
Expand All @@ -155,7 +156,7 @@ int FileSystem::findAll(String const &path, FoundFiles &found) const
dir = "/" + dir;
}

DENG2_FS_GUARD_INDEX();
DENG2_FS_GUARD_INDEX_R();

ConstIndexRange range = d->index.equal_range(baseName);
for(Index::const_iterator i = range.first; i != range.second; ++i)
Expand All @@ -176,7 +177,7 @@ File &FileSystem::find(String const &path) const

void FileSystem::index(File &file)
{
DENG2_FS_GUARD_INDEX();
DENG2_FS_GUARD_INDEX_W();

String const lowercaseName = file.name().lower();

Expand All @@ -192,7 +193,7 @@ static void removeFromIndex(FileSystem::Index &idx, File &file)
if(idx.empty())
{
return;
}
}

// Look up the ones that might be this file.
FileSystem::IndexRange range = idx.equal_range(file.name().lower());
Expand All @@ -210,7 +211,7 @@ static void removeFromIndex(FileSystem::Index &idx, File &file)

void FileSystem::deindex(File &file)
{
DENG2_FS_GUARD_INDEX();
DENG2_FS_GUARD_INDEX_W();

removeFromIndex(d->index, file);
removeFromIndex(d->typeIndex[DENG2_TYPE_NAME(file)], file);
Expand All @@ -223,7 +224,7 @@ void FileSystem::timeChanged(Clock const &)

FileSystem::Index const &FileSystem::indexFor(String const &typeName) const
{
DENG2_FS_GUARD_INDEX();
DENG2_FS_GUARD_INDEX_R();

Instance::TypeIndex::const_iterator found = d->typeIndex.find(typeName);
if(found != d->typeIndex.end())
Expand All @@ -239,7 +240,7 @@ FileSystem::Index const &FileSystem::indexFor(String const &typeName) const

void FileSystem::printIndex()
{
DENG2_FS_GUARD_INDEX();
DENG2_FS_GUARD_INDEX_R();

LOG_DEBUG("Main FS index has %i entries") << d->index.size();

Expand Down

0 comments on commit 1c8af51

Please sign in to comment.