Make cache refcounting threadsafe
This commit is contained in:
parent
31ee38e541
commit
8d2bbb193a
|
@ -117,6 +117,7 @@ typedef struct _FcRef { fc_atomic_int_t count; } FcRef;
|
|||
static inline void FcRefInit (FcRef *r, int v) { r->count = v; }
|
||||
static inline int FcRefInc (FcRef *r) { return fc_atomic_int_add (r->count, +1); }
|
||||
static inline int FcRefDec (FcRef *r) { return fc_atomic_int_add (r->count, -1); }
|
||||
static inline int FcRefAdd (FcRef *r, int v) { return fc_atomic_int_add (r->count, v); }
|
||||
static inline void FcRefSetConst (FcRef *r) { r->count = FC_REF_CONSTANT_VALUE; }
|
||||
static inline FcBool FcRefIsConst (const FcRef *r) { return r->count == FC_REF_CONSTANT_VALUE; }
|
||||
|
||||
|
|
|
@ -233,7 +233,7 @@ typedef struct _FcCacheSkip FcCacheSkip;
|
|||
|
||||
struct _FcCacheSkip {
|
||||
FcCache *cache;
|
||||
int ref;
|
||||
FcRef ref;
|
||||
intptr_t size;
|
||||
dev_t cache_dev;
|
||||
ino_t cache_ino;
|
||||
|
@ -368,7 +368,7 @@ FcCacheInsert (FcCache *cache, struct stat *cache_stat)
|
|||
|
||||
s->cache = cache;
|
||||
s->size = cache->size;
|
||||
s->ref = 1;
|
||||
FcRefInit (&s->ref, 1);
|
||||
if (cache_stat)
|
||||
{
|
||||
s->cache_dev = cache_stat->st_dev;
|
||||
|
@ -451,7 +451,7 @@ FcCacheFindByStat (struct stat *cache_stat)
|
|||
s->cache_ino == cache_stat->st_ino &&
|
||||
s->cache_mtime == cache_stat->st_mtime)
|
||||
{
|
||||
s->ref++;
|
||||
FcRefInc (&s->ref);
|
||||
return s->cache;
|
||||
}
|
||||
return NULL;
|
||||
|
@ -481,7 +481,7 @@ FcCacheObjectReference (void *object)
|
|||
FcCacheSkip *skip = FcCacheFindByAddr (object);
|
||||
|
||||
if (skip)
|
||||
skip->ref++;
|
||||
FcRefInc (&skip->ref);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -491,8 +491,7 @@ FcCacheObjectDereference (void *object)
|
|||
|
||||
if (skip)
|
||||
{
|
||||
skip->ref--;
|
||||
if (skip->ref <= 0)
|
||||
if (FcRefDec (&skip->ref) <= 1)
|
||||
FcDirCacheDispose (skip->cache);
|
||||
}
|
||||
}
|
||||
|
@ -618,7 +617,7 @@ FcDirCacheReference (FcCache *cache, int nref)
|
|||
FcCacheSkip *skip = FcCacheFindByAddr (cache);
|
||||
|
||||
if (skip)
|
||||
skip->ref += nref;
|
||||
FcRefAdd (&skip->ref, nref);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in New Issue