Skip to content

Commit

Permalink
libcore|Bank: Avoid hanging when accessing bank contents
Browse files Browse the repository at this point in the history
It was possible to hang when checking if a bank item is loaded
while said item was currently being loaded.
  • Loading branch information
skyjake committed Aug 26, 2017
1 parent 91b102c commit d0b4d62
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 12 additions & 7 deletions doomsday/sdk/libcore/src/data/bank.cpp
Expand Up @@ -88,6 +88,11 @@ class Cache : public Lockable
_items.remove(&data);
}

bool contains(ItemType const *data) const {
DENG2_GUARD(this);
return _items.contains(const_cast<ItemType *>(data));
}

virtual void clear() {
DENG2_GUARD(this);
_items.clear();
Expand Down Expand Up @@ -162,7 +167,6 @@ DENG2_PIMPL(Bank)
/// Load the item into memory from its current cache.
void load()
{
DENG2_GUARD(this);
DENG2_ASSERT(cache != 0);

switch (cache->format())
Expand Down Expand Up @@ -401,15 +405,14 @@ DENG2_PIMPL(Bank)

DENG2_GUARD(this);

DENG2_ASSERT(item.data.get() != 0);

DENG2_ASSERT(item.data.get() != nullptr);
addBytes(item.data->sizeInMemory());
DataCache::add(item);
}

void remove(Data &item)
{
DENG2_ASSERT(item.data.get() != 0);
DENG2_ASSERT(item.data.get() != nullptr);

DENG2_GUARD(this);

Expand Down Expand Up @@ -936,9 +939,11 @@ Bank::IData &Bank::data(DotPath const &path) const

bool Bank::isLoaded(DotPath const &path) const
{
Impl::Data &item = d->items.find(path, PathTree::MatchFull | PathTree::NoBranch);
DENG2_GUARD(item);
return bool(item.data);
if (Impl::Data const *item = d->items.tryFind(path, PathTree::MatchFull | PathTree::NoBranch))
{
return d->memoryCache.contains(item);
}
return false;
}

void Bank::unload(DotPath const &path, CacheLevel toLevel, Importance importance)
Expand Down
4 changes: 0 additions & 4 deletions doomsday/sdk/libgui/src/graphics/packageiconbank.cpp
Expand Up @@ -37,10 +37,6 @@ DENG2_PIMPL_NOREF(PackageIconBank)

Image load() const override
{
// If the file system is being updated, let's hold on a second first.
// This is a background task so it doesn't hurt to delay it a little.
Folder::waitForPopulation();

String const iconPath = sourcePath() / QStringLiteral("icon");

Image img;
Expand Down

0 comments on commit d0b4d62

Please sign in to comment.