Skip to content

Commit

Permalink
Bug 1187142 - Replace nsBaseHashtable::Enumerate() calls in hal/ with…
Browse files Browse the repository at this point in the history
… iterators. r=dhylands.

--HG--
extra : rebase_source : 23f6a719bd1ed946f79b724e2c92097fd7809099
  • Loading branch information
nnethercote committed Oct 20, 2015
1 parent b05d597 commit 9a1a558
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions hal/HalWakeLock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,6 @@ CountWakeLocks(ProcessLockTable* aTable, LockCount* aTotalCount)
}
}

static PLDHashOperator
RemoveChildFromList(const nsAString& aKey, nsAutoPtr<ProcessLockTable>& aTable,
void* aUserArg)
{
MOZ_ASSERT(aUserArg);

PLDHashOperator op = PL_DHASH_NEXT;
uint64_t childID = *static_cast<uint64_t*>(aUserArg);
if (aTable->Get(childID, nullptr)) {
aTable->Remove(childID);

LockCount totalCount;
CountWakeLocks(aTable, &totalCount);
if (!totalCount.numLocks) {
op = PL_DHASH_REMOVE;
}

if (sActiveListeners) {
NotifyWakeLockChange(WakeLockInfoFromLockCount(aKey, totalCount));
}
}

return op;
}

class ClearHashtableOnShutdown final : public nsIObserver {
~ClearHashtableOnShutdown() {}
public:
Expand Down Expand Up @@ -145,7 +120,25 @@ CleanupOnContentShutdown::Observe(nsISupports* aSubject, const char* aTopic, con
nsresult rv = props->GetPropertyAsUint64(NS_LITERAL_STRING("childID"),
&childID);
if (NS_SUCCEEDED(rv)) {
sLockTable->Enumerate(RemoveChildFromList, &childID);
for (auto iter = sLockTable->Iter(); !iter.Done(); iter.Next()) {
nsAutoPtr<ProcessLockTable>& table = iter.Data();

if (table->Get(childID, nullptr)) {
table->Remove(childID);

LockCount totalCount;
CountWakeLocks(table, &totalCount);

if (sActiveListeners) {
NotifyWakeLockChange(WakeLockInfoFromLockCount(iter.Key(),
totalCount));
}

if (totalCount.numLocks == 0) {
iter.Remove();
}
}
}
} else {
NS_WARNING("ipc:content-shutdown message without childID property");
}
Expand Down

0 comments on commit 9a1a558

Please sign in to comment.