@@ -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 );
@@ -309,7 +312,7 @@ static void attr_cache__free(git_attr_cache *cache)
309312 if (!cache )
310313 return ;
311314
312- unlock = (git_mutex_lock ( & cache -> lock ) == 0 );
315+ unlock = (attr_cache_lock ( cache ) == 0 );
313316
314317 if (cache -> files != NULL ) {
315318 git_attr_file_entry * entry ;
@@ -345,13 +348,13 @@ static void attr_cache__free(git_attr_cache *cache)
345348 cache -> cfg_excl_file = NULL ;
346349
347350 if (unlock )
348- git_mutex_unlock ( & cache -> lock );
351+ attr_cache_unlock ( cache );
349352 git_mutex_free (& cache -> lock );
350353
351354 git__free (cache );
352355}
353356
354- int git_attr_cache__do_init (git_repository * repo )
357+ int git_attr_cache__init (git_repository * repo )
355358{
356359 int ret = 0 ;
357360 git_attr_cache * cache = git_repository_attr_cache (repo );
@@ -429,7 +432,7 @@ int git_attr_cache__insert_macro(git_repository *repo, git_attr_rule *macro)
429432 if (macro -> assigns .length == 0 )
430433 return 0 ;
431434
432- if (git_mutex_lock ( & cache -> lock ) < 0 ) {
435+ if (attr_cache_lock ( cache ) < 0 ) {
433436 giterr_set (GITERR_OS , "unable to get attr cache lock" );
434437 error = -1 ;
435438 } else {
0 commit comments