Add FcCacheAllocate() helper
This lets you allocate a chunk of memory that will be freed when the cache is freed. https://bugs.freedesktop.org/show_bug.cgi?id=106618
This commit is contained in:
parent
94080c3d48
commit
a63b9c622e
|
@ -443,6 +443,7 @@ struct _FcCacheSkip {
|
||||||
FcCache *cache;
|
FcCache *cache;
|
||||||
FcRef ref;
|
FcRef ref;
|
||||||
intptr_t size;
|
intptr_t size;
|
||||||
|
void *allocated;
|
||||||
dev_t cache_dev;
|
dev_t cache_dev;
|
||||||
ino_t cache_ino;
|
ino_t cache_ino;
|
||||||
time_t cache_mtime;
|
time_t cache_mtime;
|
||||||
|
@ -568,6 +569,7 @@ FcCacheInsert (FcCache *cache, struct stat *cache_stat)
|
||||||
|
|
||||||
s->cache = cache;
|
s->cache = cache;
|
||||||
s->size = cache->size;
|
s->size = cache->size;
|
||||||
|
s->allocated = NULL;
|
||||||
FcRefInit (&s->ref, 1);
|
FcRefInit (&s->ref, 1);
|
||||||
if (cache_stat)
|
if (cache_stat)
|
||||||
{
|
{
|
||||||
|
@ -642,6 +644,7 @@ FcCacheRemoveUnlocked (FcCache *cache)
|
||||||
FcCacheSkip **update[FC_CACHE_MAX_LEVEL];
|
FcCacheSkip **update[FC_CACHE_MAX_LEVEL];
|
||||||
FcCacheSkip *s, **next;
|
FcCacheSkip *s, **next;
|
||||||
int i;
|
int i;
|
||||||
|
void *allocated;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find links along each chain
|
* Find links along each chain
|
||||||
|
@ -659,6 +662,15 @@ FcCacheRemoveUnlocked (FcCache *cache)
|
||||||
*update[i] = s->next[i];
|
*update[i] = s->next[i];
|
||||||
while (fcCacheMaxLevel > 0 && fcCacheChains[fcCacheMaxLevel - 1] == NULL)
|
while (fcCacheMaxLevel > 0 && fcCacheChains[fcCacheMaxLevel - 1] == NULL)
|
||||||
fcCacheMaxLevel--;
|
fcCacheMaxLevel--;
|
||||||
|
|
||||||
|
allocated = s->allocated;
|
||||||
|
while (allocated)
|
||||||
|
{
|
||||||
|
/* First element in allocated chunk is the free list */
|
||||||
|
next = *(void **)allocated;
|
||||||
|
free (allocated);
|
||||||
|
allocated = next;
|
||||||
|
}
|
||||||
free (s);
|
free (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -728,6 +740,30 @@ FcCacheObjectDereference (void *object)
|
||||||
unlock_cache ();
|
unlock_cache ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
FcCacheAllocate (FcCache *cache, size_t len)
|
||||||
|
{
|
||||||
|
FcCacheSkip *skip;
|
||||||
|
void *allocated = NULL;
|
||||||
|
|
||||||
|
lock_cache ();
|
||||||
|
skip = FcCacheFindByAddrUnlocked (cache);
|
||||||
|
if (skip)
|
||||||
|
{
|
||||||
|
void *chunk = malloc (sizeof (void *) + len);
|
||||||
|
if (chunk)
|
||||||
|
{
|
||||||
|
/* First element in allocated chunk is the free list */
|
||||||
|
*(void **)chunk = skip->allocated;
|
||||||
|
skip->allocated = chunk;
|
||||||
|
/* Return the rest */
|
||||||
|
allocated = ((FcChar8 *)chunk) + sizeof (void *);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unlock_cache ();
|
||||||
|
return allocated;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FcCacheFini (void)
|
FcCacheFini (void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -617,9 +617,13 @@ FcCacheObjectReference (void *object);
|
||||||
FcPrivate void
|
FcPrivate void
|
||||||
FcCacheObjectDereference (void *object);
|
FcCacheObjectDereference (void *object);
|
||||||
|
|
||||||
|
FcPrivate void *
|
||||||
|
FcCacheAllocate (FcCache *cache, size_t len);
|
||||||
|
|
||||||
FcPrivate void
|
FcPrivate void
|
||||||
FcCacheFini (void);
|
FcCacheFini (void);
|
||||||
|
|
||||||
|
|
||||||
FcPrivate void
|
FcPrivate void
|
||||||
FcDirCacheReference (FcCache *cache, int nref);
|
FcDirCacheReference (FcCache *cache, int nref);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue