<util/imgcache.h>¶
Small cache of loaded program images, keyed by path.
Lets a shell spawn the same program again without re-reading it from fsd. An entry is valid while the file's size and modification time match.
#include <util/imgcache.h>
Constants¶
| Name | Value | Description |
|---|---|---|
IMGCACHE_SLOTS |
8 |
Number of images kept; the least recently used is evicted beyond that. |
IMGCACHE_PATH_MAX |
128 |
Longest path that can be cached, including the NUL. |
Structures¶
ImgCacheEntry¶
One cached image.
| Field | Type | Description |
|---|---|---|
path |
char |
Path the image was read from. |
size |
uint32_t |
File size when it was cached. |
mtime |
uint32_t |
File modification time when it was cached. |
last_used |
uint32_t |
Value of the cache clock at the last hit; for LRU eviction. |
obj |
Handle |
Memory object holding the image, or -1 if the slot is free. |
ImgCache¶
The cache. A zero-initialised ImgCache is ready to use.
| Field | Type | Description |
|---|---|---|
slots |
ImgCacheEntry |
Cached images. |
clock |
uint32_t |
Counter bumped on every hit or insert. |
ready |
bool |
Set once the slots have been initialised. |
Functions¶
ImgCacheGet¶
Handle ImgCacheGet(ImgCache *c, const char *path, uint32_t size, uint32_t mtime);
Looks up the image cached for path.
An entry whose size or mtime no longer matches is dropped and counts as a miss.
| Parameter | Direction | Description |
|---|---|---|
c |
inout | The cache. |
path |
in | Path of the program. |
size |
in | Current file size. |
mtime |
in | Current file modification time. |
Returns: The image object, still owned by the cache, or -1 on a miss.
ImgCachePut¶
bool ImgCachePut(ImgCache *c, const char *path, uint32_t size, uint32_t mtime, Handle obj);
Caches obj under path and takes ownership of it.
Replaces any previous entry for path; when every slot is taken, closes the least recently used entry.
| Parameter | Direction | Description |
|---|---|---|
c |
inout | The cache. |
path |
in | Path of the program. |
size |
in | File size. |
mtime |
in | File modification time. |
obj |
in | Memory object holding the image. |
Returns: true if cached; false if path is too long, and the caller still owns obj.
ImgCacheDrop¶
void ImgCacheDrop(ImgCache *c, const char *path);
Closes and forgets the entry for path, if any.
| Parameter | Direction | Description |
|---|---|---|
c |
inout | The cache. |
path |
in | Path of the program. |