Ptex
PtexCache.cpp File Reference

Ptex Cache Implementation. More...

#include "PtexPlatform.h"
#include <algorithm>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <iostream>
#include <ctype.h>
#include "Ptexture.h"
#include "PtexReader.h"
#include "PtexCache.h"

Go to the source code of this file.

Detailed Description

Ptex Cache Implementation.

Ownership. The cache owns all files and data. If a texture is in use, the cache will not touch it. When it is no longer in use, it may be kept or deleted to keep resource usage under the set limits. Deletions are done in lru order.

Resource Tracking. All textures are created as part of the cache and have a ptr back to the cache. Each texture updates the cache's resource total whenever it is released to the cache.

Reference Counting. Every texture has a ref count to track whether it is being used. Objects belonging to the texture (such as texture tiles or meta data) are not ref-counted and are kept at least as long as the texture is in use.

Cache Lifetime. When a cache is released from its owner, it will delete itself and all contained textures immediately.

Threading. The cache is fully thread-safe and completely lock/wait/atomic-free for accessing data that is present in the cache. Acquiring a texture from PtexCache::get requires an atomic increment of the refcount. Releasing the texture requires an atomic decrement and potentially a brief spinlock to add the texture to a list of recent textures.

Definition in file PtexCache.cpp.