00001 // Filename: geomCacheManager.h 00002 // Created by: drose (11Mar05) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef GEOMCACHEMANAGER_H 00016 #define GEOMCACHEMANAGER_H 00017 00018 #include "pandabase.h" 00019 #include "config_gobj.h" 00020 #include "lightMutex.h" 00021 #include "pStatCollector.h" 00022 00023 class GeomCacheEntry; 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Class : GeomCacheManager 00027 // Description : This is used to keep track of, and limit the size of, 00028 // the cache of munged vertices, which would otherwise 00029 // be distributed through all of the GeomVertexData 00030 // objects in the system. 00031 // 00032 // The actual data in the cache is not stored here, but 00033 // rather it is distributed among the various 00034 // GeomVertexData source objects. This allows the cache 00035 // data to propagate through the multiprocess pipeline. 00036 // 00037 // This structure actually caches any of a number of 00038 // different types of pointers, and mixes them all up in 00039 // the same LRU cache list. Some of them (such as 00040 // GeomMunger) are reference-counted here in the cache; 00041 // most are not. 00042 //////////////////////////////////////////////////////////////////// 00043 class EXPCL_PANDA_GOBJ GeomCacheManager { 00044 protected: 00045 GeomCacheManager(); 00046 ~GeomCacheManager(); 00047 00048 PUBLISHED: 00049 INLINE void set_max_size(int max_size) const; 00050 INLINE int get_max_size() const; 00051 00052 INLINE int get_total_size() const; 00053 00054 void flush(); 00055 00056 static GeomCacheManager *get_global_ptr(); 00057 00058 public: 00059 INLINE void evict_old_entries(); 00060 void evict_old_entries(int max_size, bool keep_current); 00061 INLINE static void flush_level(); 00062 00063 private: 00064 // This mutex protects all operations on this object, especially the 00065 // linked-list operations. 00066 LightMutex _lock; 00067 00068 int _total_size; 00069 00070 // We maintain a doubly-linked list to keep the cache entries in 00071 // least-recently-used order: the items at the head of the list are 00072 // ready to be flushed. We use our own doubly-linked list instead 00073 // of an STL list, just so we can avoid a tiny bit of overhead, 00074 // especially in keeping the pointer directly into the list from the 00075 // calling objects. 00076 00077 // The tail and the head of the list are both kept by the _prev and 00078 // _next pointers, respectively, within the following object, which 00079 // always exists solely to keep a handle to the list. Keeping a 00080 // token of the list this way avoids special cases for an empty 00081 // list. 00082 GeomCacheEntry *_list; 00083 00084 static GeomCacheManager *_global_ptr; 00085 00086 public: 00087 static PStatCollector _geom_cache_size_pcollector; 00088 static PStatCollector _geom_cache_active_pcollector; 00089 static PStatCollector _geom_cache_record_pcollector; 00090 static PStatCollector _geom_cache_erase_pcollector; 00091 static PStatCollector _geom_cache_evict_pcollector; 00092 00093 friend class GeomCacheEntry; 00094 }; 00095 00096 #include "geomCacheManager.I" 00097 00098 #endif