mirror of
https://github.com/wolfpld/tracy.git
synced 2026-10-16 05:45:26 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user