46 #define USE_SPIN // use spinlocks instead of mutex for main cache lock 
   82         static void inc(
int& val) {
 
   87         static void add(
long int& val, 
int inc) {
 
   93     extern CacheStats stats;
 
   94 #define STATS_INC(x) stats.inc(stats.x); 
   95 #define STATS_ADD(x, y) stats.add(stats.x, y); 
   98 #define STATS_ADD(x, y) 
  112         assert(p && *p == 
this);
 
  113         if (!inuse()) 
delete this;
 
  118         for (
typename T::iterator i=list.begin(); i != list.end(); i++) {
 
  121                 assert(obj->
_parent == (
void**)&*i);
 
  129         : _parent(parent), _prev(0), _next(0) {}
 
  133         if (_parent) { assert(*_parent == 
this); *_parent = 0; }
 
  136             _prev->_next = _next; 
 
  137             _next->_prev = _prev;
 
  168         if (!node->
_parent) 
delete node;
 
  180         if (_end._next == &_end) 
return 0;
 
  195         : _pendingDelete(false),
 
  196           _maxFiles(maxFiles), _unusedFileCount(0),
 
  197           _maxDataSize(maxMem),
 
  198           _unusedDataSize(0), _unusedDataCount(0)
 
  208         _minDataCount = 10 * maxFiles;
 
  210         if (_minDataCount > 1000) _minDataCount = 1000;
 
  230     void removeData(
int size);
 
  233         while (_unusedFileCount > _maxFiles) 
 
  235             if (!_unusedFiles.pop()) 
break;
 
  241         while ((_unusedDataSize > _maxDataSize) &&
 
  242                (_unusedDataCount > _minDataCount))
 
  244             if (!_unusedData.pop()) 
break;
 
  270     { _cache->addFile(); }
 
  271     void ref() { assert(_cache->cachelock.locked()); 
if (!_refcount++) _cache->setFileInUse(
this); }
 
  272     void unref() { assert(_cache->cachelock.locked()); 
if (!--_refcount) _cache->setFileUnused(
this); }
 
  286         : 
PtexLruItem(parent), _cache(cache), _refcount(1), _size(size)
 
  287     { _cache->addData(); }
 
  288     void ref() { assert(_cache->cachelock.locked()); 
if (!_refcount++) _cache->setDataInUse(
this, _size); }
 
  289     void unref() { assert(_cache->cachelock.locked()); 
if (!--_refcount) _cache->setDataUnused(
this, _size); }
 
void handlePendingDelete()
File-handle and memory cache for reading ptex files. 
virtual ~PtexCachedFile()
PtexCachedFile(void **parent, PtexCacheImpl *cache)
virtual ~PtexCachedData()
void push(PtexLruItem *node)
Cache entry for allocated memory block. 
One item in a cache, typically an open file or a block of memory. 
static void orphanList(T &list)
virtual void release()
Release resources held by this pointer (pointer becomes invalid). 
AutoLock< CacheLock > AutoLockCache
PtexCachedData(void **parent, PtexCacheImpl *cache, int size)
Cache entry for open file handle. 
Ptex cache implementation. 
Contains PtexDict, a string-keyed hash table. 
Automatically acquire and release lock within enclosing scope. 
PtexLruItem(void **parent=0)
PtexCacheImpl(int maxFiles, int maxMem)
A list of items kept in least-recently-used (LRU) order. 
Public API classes for reading, writing, caching, and filtering Ptex files. 
void extract(PtexLruItem *node)