From 94570f20aada7cd4f0121390a9397e6cd28d2fbe Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 5 Feb 2022 22:07:58 +0100 Subject: [PATCH] pgraph: Remove need for grabbing lock in RenderState destructor --- panda/src/pgraph/cacheStats.I | 2 +- panda/src/pgraph/cacheStats.cxx | 5 +++-- panda/src/pgraph/cacheStats.h | 3 ++- panda/src/pgraph/renderState.cxx | 2 -- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/panda/src/pgraph/cacheStats.I b/panda/src/pgraph/cacheStats.I index e84ff83878..9cd08c4b3f 100644 --- a/panda/src/pgraph/cacheStats.I +++ b/panda/src/pgraph/cacheStats.I @@ -90,6 +90,6 @@ add_total_size(int count) { INLINE void CacheStats:: add_num_states(int count) { #ifndef NDEBUG - _num_states += count; + _num_states.fetch_add(count, std::memory_order_relaxed); #endif // NDEBUG } diff --git a/panda/src/pgraph/cacheStats.cxx b/panda/src/pgraph/cacheStats.cxx index 4721171e86..118e469c9d 100644 --- a/panda/src/pgraph/cacheStats.cxx +++ b/panda/src/pgraph/cacheStats.cxx @@ -51,12 +51,13 @@ reset(double now) { void CacheStats:: write(std::ostream &out, const char *name) const { #ifndef NDEBUG + int num_states = _num_states.load(std::memory_order_relaxed); out << name << " cache: " << _cache_hits << " hits, " << _cache_misses << " misses\n" << _cache_adds + _cache_new_adds << "(" << _cache_new_adds << ") adds(new), " << _cache_dels << " dels, " - << _total_cache_size << " / " << _num_states << " = " - << (double)_total_cache_size / (double)_num_states + << _total_cache_size << " / " << num_states << " = " + << (double)_total_cache_size / (double)num_states << " average cache size\n"; #endif // NDEBUG } diff --git a/panda/src/pgraph/cacheStats.h b/panda/src/pgraph/cacheStats.h index daeeb5340d..2812bbed4e 100644 --- a/panda/src/pgraph/cacheStats.h +++ b/panda/src/pgraph/cacheStats.h @@ -16,6 +16,7 @@ #include "pandabase.h" #include "clockObject.h" +#include "patomic.h" #include "pnotify.h" /** @@ -45,7 +46,7 @@ private: int _cache_new_adds = 0; int _cache_dels = 0; int _total_cache_size = 0; - int _num_states = 0; + patomic _num_states {0}; double _last_reset = 0.0; bool _cache_report = false; diff --git a/panda/src/pgraph/renderState.cxx b/panda/src/pgraph/renderState.cxx index 805892b947..76884ea0bb 100644 --- a/panda/src/pgraph/renderState.cxx +++ b/panda/src/pgraph/renderState.cxx @@ -117,8 +117,6 @@ RenderState:: nassertv(!is_destructing()); set_destructing(); - LightReMutexHolder holder(*_states_lock); - // unref() should have cleared these. nassertv(_saved_entry == -1); nassertv(_composition_cache.is_empty() && _invert_composition_cache.is_empty());