Skip to content

Commit c115101

Browse files
committed
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.
1 parent b8ab782 commit c115101

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/attrcache.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,11 @@ static int attr_cache_upsert(git_attr_cache *cache, git_attr_file *file)
103103
GIT_REFCOUNT_OWN(file, entry);
104104
GIT_REFCOUNT_INC(file);
105105

106-
old = git__compare_and_swap(
107-
&entry->file[file->source], entry->file[file->source], file);
106+
/*
107+
* Replace the existing value if another thread has
108+
* created it in the meantime.
109+
*/
110+
old = git__swap(entry->file[file->source], file);
108111

109112
if (old) {
110113
GIT_REFCOUNT_OWN(old, NULL);

0 commit comments

Comments
 (0)