Browse Source

pgraph: Remove need for grabbing lock in RenderState destructor

rdb 3 years ago
parent
commit
94570f20aa

+ 1 - 1
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
 }

+ 3 - 2
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
 }

+ 2 - 1
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<int> _num_states {0};
   double _last_reset = 0.0;
 
   bool _cache_report = false;

+ 0 - 2
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());