Skip to content

Commit c03f00e

Browse files
authored
Merge pull request libgit2#4131 from pks-t/pks/attrcache-cleanups
Attrcache cleanups
2 parents 86201b9 + ce6f61d commit c03f00e

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/attrcache.c

Lines changed: 9 additions & 6 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);
@@ -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 {

src/attrcache.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ typedef struct {
2222
git_pool pool;
2323
} git_attr_cache;
2424

25-
extern int git_attr_cache__do_init(git_repository *repo);
26-
27-
#define git_attr_cache__init(REPO) \
28-
(git_repository_attr_cache(REPO) ? 0 : git_attr_cache__do_init(REPO))
25+
extern int git_attr_cache__init(git_repository *repo);
2926

3027
/* get file - loading and reload as needed */
3128
extern int git_attr_cache__get(

0 commit comments

Comments
 (0)