Replace uuid in the table properly when -r
This commit is contained in:
parent
0378790ca3
commit
8ab4d67995
|
@ -62,6 +62,7 @@ FcDirCacheCreateUUID (FcChar8 *dir,
|
||||||
int fd;
|
int fd;
|
||||||
uuid_t uuid;
|
uuid_t uuid;
|
||||||
char out[37];
|
char out[37];
|
||||||
|
FcBool (* hash_add) (FcHashTable *, void*, void*);
|
||||||
|
|
||||||
atomic = FcAtomicCreate (uuidname);
|
atomic = FcAtomicCreate (uuidname);
|
||||||
if (!atomic)
|
if (!atomic)
|
||||||
|
@ -81,7 +82,11 @@ FcDirCacheCreateUUID (FcChar8 *dir,
|
||||||
goto bail3;
|
goto bail3;
|
||||||
}
|
}
|
||||||
uuid_generate_random (uuid);
|
uuid_generate_random (uuid);
|
||||||
if (!FcHashTableAdd (config->uuid_table, dir, uuid))
|
if (force)
|
||||||
|
hash_add = FcHashTableReplace;
|
||||||
|
else
|
||||||
|
hash_add = FcHashTableAdd;
|
||||||
|
if (!hash_add (config->uuid_table, dir, uuid))
|
||||||
{
|
{
|
||||||
ret = FcFalse;
|
ret = FcFalse;
|
||||||
goto bail3;
|
goto bail3;
|
||||||
|
|
35
src/fchash.c
35
src/fchash.c
|
@ -137,10 +137,11 @@ FcHashTableFind (FcHashTable *table,
|
||||||
return FcFalse;
|
return FcFalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
FcBool
|
static FcBool
|
||||||
FcHashTableAdd (FcHashTable *table,
|
FcHashTableAddInternal (FcHashTable *table,
|
||||||
void *key,
|
void *key,
|
||||||
void *value)
|
void *value,
|
||||||
|
FcBool replace)
|
||||||
{
|
{
|
||||||
FcHashBucket **prev, *bucket, *b;
|
FcHashBucket **prev, *bucket, *b;
|
||||||
FcChar32 hash = table->hash_func (key);
|
FcChar32 hash = table->hash_func (key);
|
||||||
|
@ -167,17 +168,43 @@ FcHashTableAdd (FcHashTable *table,
|
||||||
table->value_destroy_func (bucket->value);
|
table->value_destroy_func (bucket->value);
|
||||||
free (bucket);
|
free (bucket);
|
||||||
|
|
||||||
return FcFalse;
|
return !ret;
|
||||||
}
|
}
|
||||||
retry:
|
retry:
|
||||||
for (prev = &table->buckets[hash % FC_HASH_SIZE];
|
for (prev = &table->buckets[hash % FC_HASH_SIZE];
|
||||||
(b = fc_atomic_ptr_get (prev)); prev = &(b->next))
|
(b = fc_atomic_ptr_get (prev)); prev = &(b->next))
|
||||||
{
|
{
|
||||||
if (!table->compare_func (bucket->key, key))
|
if (!table->compare_func (bucket->key, key))
|
||||||
|
{
|
||||||
|
if (replace)
|
||||||
|
{
|
||||||
|
if (!fc_atomic_ptr_cmpexch (prev, b, bucket))
|
||||||
|
goto retry;
|
||||||
|
bucket = b;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ret = FcTrue;
|
||||||
goto destroy;
|
goto destroy;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!fc_atomic_ptr_cmpexch (prev, b, bucket))
|
if (!fc_atomic_ptr_cmpexch (prev, b, bucket))
|
||||||
goto retry;
|
goto retry;
|
||||||
|
|
||||||
return FcTrue;
|
return FcTrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FcBool
|
||||||
|
FcHashTableAdd (FcHashTable *table,
|
||||||
|
void *key,
|
||||||
|
void *value)
|
||||||
|
{
|
||||||
|
return FcHashTableAddInternal (table, key, value, FcFalse);
|
||||||
|
}
|
||||||
|
|
||||||
|
FcBool
|
||||||
|
FcHashTableReplace (FcHashTable *table,
|
||||||
|
void *key,
|
||||||
|
void *value)
|
||||||
|
{
|
||||||
|
return FcHashTableAddInternal (table, key, value, FcTrue);
|
||||||
|
}
|
||||||
|
|
|
@ -1335,5 +1335,9 @@ FcHashTableAdd (FcHashTable *table,
|
||||||
void *key,
|
void *key,
|
||||||
void *value);
|
void *value);
|
||||||
|
|
||||||
|
FcPrivate FcBool
|
||||||
|
FcHashTableReplace (FcHashTable *table,
|
||||||
|
void *key,
|
||||||
|
void *value);
|
||||||
|
|
||||||
#endif /* _FC_INT_H_ */
|
#endif /* _FC_INT_H_ */
|
||||||
|
|
Loading…
Reference in New Issue