pgraph: Remove need for grabbing lock in RenderState destructor

This commit is contained in:
rdb 2022-02-05 22:07:58 +01:00
parent 4e925a839a
commit 94570f20aa
4 changed files with 6 additions and 6 deletions

View File

@ -90,6 +90,6 @@ add_total_size(int count) {
INLINE void CacheStats:: INLINE void CacheStats::
add_num_states(int count) { add_num_states(int count) {
#ifndef NDEBUG #ifndef NDEBUG
_num_states += count; _num_states.fetch_add(count, std::memory_order_relaxed);
#endif // NDEBUG #endif // NDEBUG
} }

View File

@ -51,12 +51,13 @@ reset(double now) {
void CacheStats:: void CacheStats::
write(std::ostream &out, const char *name) const { write(std::ostream &out, const char *name) const {
#ifndef NDEBUG #ifndef NDEBUG
int num_states = _num_states.load(std::memory_order_relaxed);
out << name << " cache: " << _cache_hits << " hits, " out << name << " cache: " << _cache_hits << " hits, "
<< _cache_misses << " misses\n" << _cache_misses << " misses\n"
<< _cache_adds + _cache_new_adds << "(" << _cache_new_adds << ") adds(new), " << _cache_adds + _cache_new_adds << "(" << _cache_new_adds << ") adds(new), "
<< _cache_dels << " dels, " << _cache_dels << " dels, "
<< _total_cache_size << " / " << _num_states << " = " << _total_cache_size << " / " << num_states << " = "
<< (double)_total_cache_size / (double)_num_states << (double)_total_cache_size / (double)num_states
<< " average cache size\n"; << " average cache size\n";
#endif // NDEBUG #endif // NDEBUG
} }

View File

@ -16,6 +16,7 @@
#include "pandabase.h" #include "pandabase.h"
#include "clockObject.h" #include "clockObject.h"
#include "patomic.h"
#include "pnotify.h" #include "pnotify.h"
/** /**
@ -45,7 +46,7 @@ private:
int _cache_new_adds = 0; int _cache_new_adds = 0;
int _cache_dels = 0; int _cache_dels = 0;
int _total_cache_size = 0; int _total_cache_size = 0;
int _num_states = 0; patomic<int> _num_states {0};
double _last_reset = 0.0; double _last_reset = 0.0;
bool _cache_report = false; bool _cache_report = false;

View File

@ -117,8 +117,6 @@ RenderState::
nassertv(!is_destructing()); nassertv(!is_destructing());
set_destructing(); set_destructing();
LightReMutexHolder holder(*_states_lock);
// unref() should have cleared these. // unref() should have cleared these.
nassertv(_saved_entry == -1); nassertv(_saved_entry == -1);
nassertv(_composition_cache.is_empty() && _invert_composition_cache.is_empty()); nassertv(_composition_cache.is_empty() && _invert_composition_cache.is_empty());