Commit 406254d7 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Make DUMP_HASHTABLE_STATS* buildable.

clang produces errors for conditional mutex locking in
HashTableStats::recordCollisionAtCount() and
HashTableStats::DumpStats().

> .../wtf/HashTable.cpp:56:7: error: mutex 'hashTableStatsMutex()' is not held on every path through here [-Werror,-Wthread-safety-analysis]
>   if (count > maxCollisions)
>       ^

Avoid such errors by moving lock() and unlock() into a single block.

This CL has no behavior changes.

Change-Id: If64ca5700bda0d881fd96ee84b8115b419a8aa63
Reviewed-on: https://chromium-review.googlesource.com/974667Reviewed-by: default avatarYuta Kitamura <yutak@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545032}
parent 0efc9daf
...@@ -49,25 +49,32 @@ void HashTableStats::copy(const HashTableStats* other) { ...@@ -49,25 +49,32 @@ void HashTableStats::copy(const HashTableStats* other) {
void HashTableStats::recordCollisionAtCount(int count) { void HashTableStats::recordCollisionAtCount(int count) {
// The global hash table singleton needs to be atomically updated. // The global hash table singleton needs to be atomically updated.
bool isGlobalSingleton = this == &instance(); if (this == &instance()) {
if (isGlobalSingleton) MutexLocker locker(hashTableStatsMutex());
hashTableStatsMutex().lock(); RecordCollisionAtCountWithoutLock(count);
} else {
RecordCollisionAtCountWithoutLock(count);
}
}
void HashTableStats::RecordCollisionAtCountWithoutLock(int count) {
if (count > maxCollisions) if (count > maxCollisions)
maxCollisions = count; maxCollisions = count;
numCollisions++; numCollisions++;
collisionGraph[count]++; collisionGraph[count]++;
if (isGlobalSingleton)
hashTableStatsMutex().unlock();
} }
void HashTableStats::DumpStats() { void HashTableStats::DumpStats() {
// Lock the global hash table singleton while dumping. // Lock the global hash table singleton while dumping.
bool isGlobalSingleton = this == &instance(); if (this == &instance()) {
if (isGlobalSingleton) MutexLocker locker(hashTableStatsMutex());
hashTableStatsMutex().lock(); DumpStatsWithoutLock();
} else {
DumpStatsWithoutLock();
}
}
void HashTableStats::DumpStatsWithoutLock() {
DeprecatedDataLogF("\nWTF::HashTable statistics\n\n"); DeprecatedDataLogF("\nWTF::HashTable statistics\n\n");
DeprecatedDataLogF("%d accesses\n", numAccesses); DeprecatedDataLogF("%d accesses\n", numAccesses);
DeprecatedDataLogF("%d total collisions, average %.2f probes per access\n", DeprecatedDataLogF("%d total collisions, average %.2f probes per access\n",
...@@ -84,9 +91,6 @@ void HashTableStats::DumpStats() { ...@@ -84,9 +91,6 @@ void HashTableStats::DumpStats() {
} }
DeprecatedDataLogF("%d rehashes\n", numRehashes); DeprecatedDataLogF("%d rehashes\n", numRehashes);
DeprecatedDataLogF("%d reinserts\n", numReinserts); DeprecatedDataLogF("%d reinserts\n", numReinserts);
if (isGlobalSingleton)
hashTableStatsMutex().unlock();
} }
} // namespace WTF } // namespace WTF
......
...@@ -136,6 +136,10 @@ struct WTF_EXPORT HashTableStats { ...@@ -136,6 +136,10 @@ struct WTF_EXPORT HashTableStats {
template <typename VisitorDispatcher> template <typename VisitorDispatcher>
void trace(VisitorDispatcher) {} void trace(VisitorDispatcher) {}
private:
void RecordCollisionAtCountWithoutLock(int count);
void DumpStatsWithoutLock();
}; };
#if DUMP_HASHTABLE_STATS_PER_TABLE #if DUMP_HASHTABLE_STATS_PER_TABLE
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment