summaryrefslogtreecommitdiff
path: root/src/fchash.c
diff options
context:
space:
mode:
authorAkira TAGOH <akira@tagoh.org>2017-12-18 20:05:14 +0900
committerAkira TAGOH <akira@tagoh.org>2017-12-18 20:05:14 +0900
commit8ab4d679959815feb0c383e1e17953fe1c46091f (patch)
treeed516896998b3f2c0a02adafa708e63e1592f60b /src/fchash.c
parent0378790ca362757061bff83c8a344991f1f829c6 (diff)
downloadfontconfig-8ab4d679959815feb0c383e1e17953fe1c46091f.tar.gz
Replace uuid in the table properly when -r
Diffstat (limited to 'src/fchash.c')
-rw-r--r--src/fchash.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/fchash.c b/src/fchash.c
index 54e2334..32e59c5 100644
--- a/src/fchash.c
+++ b/src/fchash.c
@@ -137,10 +137,11 @@ FcHashTableFind (FcHashTable *table,
return FcFalse;
}
-FcBool
-FcHashTableAdd (FcHashTable *table,
- void *key,
- void *value)
+static FcBool
+FcHashTableAddInternal (FcHashTable *table,
+ void *key,
+ void *value,
+ FcBool replace)
{
FcHashBucket **prev, *bucket, *b;
FcChar32 hash = table->hash_func (key);
@@ -167,17 +168,43 @@ FcHashTableAdd (FcHashTable *table,
table->value_destroy_func (bucket->value);
free (bucket);
- return FcFalse;
+ return !ret;
}
retry:
for (prev = &table->buckets[hash % FC_HASH_SIZE];
(b = fc_atomic_ptr_get (prev)); prev = &(b->next))
{
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;
+ }
}
if (!fc_atomic_ptr_cmpexch (prev, b, bucket))
goto retry;
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);
+}