15 #include "geomCacheManager.h"
16 #include "geomCacheEntry.h"
17 #include "lightMutexHolder.h"
18 #include "clockObject.h"
22 PStatCollector GeomCacheManager::_geom_cache_size_pcollector(
"Geom cache size");
23 PStatCollector GeomCacheManager::_geom_cache_active_pcollector(
"Geom cache size:Active");
24 PStatCollector GeomCacheManager::_geom_cache_record_pcollector(
"Geom cache operations:record");
25 PStatCollector GeomCacheManager::_geom_cache_erase_pcollector(
"Geom cache operations:erase");
26 PStatCollector GeomCacheManager::_geom_cache_evict_pcollector(
"Geom cache operations:evict");
35 _lock(
"GeomCacheManager"),
91 int min_frames = geom_cache_min_frames;
93 while (_total_size > max_size) {
95 nassertv(entry != _list);
97 if (keep_current && current_frame - entry->_last_frame_used < min_frames) {
99 if (gobj_cat.is_debug()) {
101 <<
"Oldest element in cache is "
102 << current_frame - entry->_last_frame_used
103 <<
" frames; keeping cache at " << _total_size <<
" entries.\n";
110 if (gobj_cat.is_debug()) {
112 <<
"cache total_size = " << _total_size <<
" entries, max_size = "
113 << max_size <<
", removing " << *entry <<
"\n";
116 entry->evict_callback();
119 if (entry->_last_frame_used == current_frame) {
120 GeomCacheManager::_geom_cache_active_pcollector.sub_level(1);
125 entry->remove_from_list();
126 _geom_cache_evict_pcollector.add_level(1);
128 _geom_cache_size_pcollector.set_level(_total_size);
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
A lightweight class that represents a single element that may be timed and/or counted via stats...
Similar to MutexHolder, but for a light mutex.
This is used to keep track of, and limit the size of, the cache of munged vertices, which would otherwise be distributed through all of the GeomVertexData objects in the system.
int get_frame_count(Thread *current_thread=Thread::get_current_thread()) const
Returns the number of times tick() has been called since the ClockObject was created, or since it was last reset.
void flush()
Immediately empties all elements in the cache.
void evict_old_entries()
Trims the cache size down to get_max_size() by evicting old cache entries as needed.
static bool is_connected()
Returns true if the client believes it is connected to a working PStatServer, false otherwise...
void ref() const
Explicitly increments the reference count.
This object contains a single cache entry in the GeomCacheManager.
static GeomCacheManager * get_global_ptr()
Returns the global cache manager pointer.