Skip to content

Commit 5699ef8

Browse files
authored
Merge pull request libgit2#5595 from lhchavez/odb-race-free
Make the odb race-free
2 parents ef6de8d + 4ae41f9 commit 5699ef8

File tree

6 files changed

+235
-67
lines changed

6 files changed

+235
-67
lines changed

script/thread-sanitizer.supp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ deadlock:attr_cache_lock
88
# data races.
99
called_from_lib:libc.so.6
1010

11-
# TODO(#5595): Remove these once the fixes land.
12-
race:src/odb.c
13-
race:git_repository_odb__weakptr
14-
race:cache_store
15-
16-
# TODO(#5595): Investigate and fix this. It can be triggered by the `thread`
11+
# TODO(#5592): Investigate and fix this. It can be triggered by the `thread`
1712
# test suite.
1813
race:git_filter_list__load_ext

src/config_cache.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,18 @@ int git_config__configmap_lookup(int *out, git_config *config, git_configmap_ite
111111

112112
int git_repository__configmap_lookup(int *out, git_repository *repo, git_configmap_item item)
113113
{
114-
*out = repo->configmap_cache[(int)item];
114+
*out = (int)(intptr_t)git__load(repo->configmap_cache[(int)item]);
115115

116116
if (*out == GIT_CONFIGMAP_NOT_CACHED) {
117117
int error;
118+
int oldval = GIT_CONFIGMAP_NOT_CACHED;
118119
git_config *config;
119120

120121
if ((error = git_repository_config__weakptr(&config, repo)) < 0 ||
121122
(error = git_config__configmap_lookup(out, config, item)) < 0)
122123
return error;
123124

124-
repo->configmap_cache[(int)item] = *out;
125+
git__compare_and_swap(&repo->configmap_cache[(int)item], &oldval, out);
125126
}
126127

127128
return 0;

0 commit comments

Comments
 (0)