diff options
author | Patrick Steinhardt <ps@pks.im> | 2017-02-21 11:52:15 +0100 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2017-02-21 16:17:36 +0100 |
commit | c11510103d9510f1a4b6e3da90464bcef52250c9 (patch) | |
tree | d391f84464931c5472322a41fa61c83c57f95a51 | |
parent | b8ab782a6dc206101d78852036a8e86d5b812278 (diff) | |
download | libgit2-c11510103d9510f1a4b6e3da90464bcef52250c9.tar.gz |
attrcache: replace existing file entry with `git__swap`
When doing an upsert of a file, we used to use `git__compare_and_swap`,
comparing the entry's file which is to be replaced with itself. This can
be more easily formulated by using `git__swap`, which unconditionally
replaces the value.
-rw-r--r-- | src/attrcache.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/attrcache.c b/src/attrcache.c index d460db80c..1812376ea 100644 --- a/src/attrcache.c +++ b/src/attrcache.c @@ -103,8 +103,11 @@ static int attr_cache_upsert(git_attr_cache *cache, git_attr_file *file) GIT_REFCOUNT_OWN(file, entry); GIT_REFCOUNT_INC(file); - old = git__compare_and_swap( - &entry->file[file->source], entry->file[file->source], file); + /* + * Replace the existing value if another thread has + * created it in the meantime. + */ + old = git__swap(entry->file[file->source], file); if (old) { GIT_REFCOUNT_OWN(old, NULL); |