Restore insert_or_assign over operator[] for graphLaunchCache

operator[] on ConcurrentHashMap returns a reference after releasing the
read lock — the subsequent assignment happens with no lock held. This is
a latent data race if the map is ever accessed from multiple threads.

insert_or_assign performs the lookup and assignment atomically under a
single write lock, which is the correct pattern for a ConcurrentHashMap.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Basil Milanich
2026-04-13 09:47:52 -05:00
parent da878d29d1
commit 8f6249c12f

View File

@@ -361,6 +361,11 @@ struct ConcurrentHashMap {
auto lock = acquire_write_lock();
return mapping.erase(key);
}
auto insert_or_assign(TKey key, TValue value) {
ZoneNamed(insert_or_assign, instrument);
auto lock = acquire_write_lock();
return mapping.insert_or_assign(std::move(key), std::move(value));
}
};
#if TRACY_CUDA_ENABLE_CUDA_CALL_STATS
@@ -990,7 +995,7 @@ namespace tracy
return false;
}
} else if (graphId != 0) {
graphLaunchCache[graphId] = apiCallInfo;
graphLaunchCache.insert_or_assign(graphId, apiCallInfo);
}
return true;
}