Skip to content

Commit ab77297

Browse files
committed
threads: give atomic functions the git_atomic prefix
1 parent 37763d3 commit ab77297

File tree

8 files changed

+39
-37
lines changed

8 files changed

+39
-37
lines changed

src/attrcache.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static int attr_cache_upsert(git_attr_cache *cache, git_attr_file *file)
108108
* Replace the existing value if another thread has
109109
* created it in the meantime.
110110
*/
111-
old = git__swap(entry->file[file->source], file);
111+
old = git_atomic_swap(entry->file[file->source], file);
112112

113113
if (old) {
114114
GIT_REFCOUNT_OWN(old, NULL);
@@ -132,7 +132,7 @@ static int attr_cache_remove(git_attr_cache *cache, git_attr_file *file)
132132
return error;
133133

134134
if ((entry = attr_cache_lookup_entry(cache, file->entry->path)) != NULL)
135-
old = git__compare_and_swap(&entry->file[file->source], file, NULL);
135+
old = git_atomic_compare_and_swap(&entry->file[file->source], file, NULL);
136136

137137
attr_cache_unlock(cache);
138138

@@ -321,7 +321,7 @@ static void attr_cache__free(git_attr_cache *cache)
321321

322322
git_strmap_foreach_value(cache->files, entry, {
323323
for (i = 0; i < GIT_ATTR_FILE_NUM_SOURCES; ++i) {
324-
if ((file = git__swap(entry->file[i], NULL)) != NULL) {
324+
if ((file = git_atomic_swap(entry->file[i], NULL)) != NULL) {
325325
GIT_REFCOUNT_OWN(file, NULL);
326326
git_attr_file__free(file);
327327
}
@@ -395,7 +395,7 @@ int git_attr_cache__init(git_repository *repo)
395395
(ret = git_pool_init(&cache->pool, 1)) < 0)
396396
goto cancel;
397397

398-
cache = git__compare_and_swap(&repo->attrcache, NULL, cache);
398+
cache = git_atomic_compare_and_swap(&repo->attrcache, NULL, cache);
399399
if (cache)
400400
goto cancel; /* raced with another thread, free this but no error */
401401

@@ -417,7 +417,7 @@ int git_attr_cache_flush(git_repository *repo)
417417
/* this could be done less expensively, but for now, we'll just free
418418
* the entire attrcache and let the next use reinitialize it...
419419
*/
420-
if (repo && (cache = git__swap(repo->attrcache, NULL)) != NULL)
420+
if (repo && (cache = git_atomic_swap(repo->attrcache, NULL)) != NULL)
421421
attr_cache__free(cache);
422422

423423
return 0;

src/config_cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ 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 = (int)(intptr_t)git__load(repo->configmap_cache[(int)item]);
114+
*out = (int)(intptr_t)git_atomic_load(repo->configmap_cache[(int)item]);
115115

116116
if (*out == GIT_CONFIGMAP_NOT_CACHED) {
117117
int error;
@@ -122,7 +122,7 @@ int git_repository__configmap_lookup(int *out, git_repository *repo, git_configm
122122
(error = git_config__configmap_lookup(out, config, item)) < 0)
123123
return error;
124124

125-
git__compare_and_swap(&repo->configmap_cache[(int)item], &oldval, out);
125+
git_atomic_compare_and_swap(&repo->configmap_cache[(int)item], &oldval, out);
126126
}
127127

128128
return 0;

src/diff_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static git_diff_driver_registry *git_repository_driver_registry(
144144
{
145145
if (!repo->diff_drivers) {
146146
git_diff_driver_registry *reg = git_diff_driver_registry_new();
147-
reg = git__compare_and_swap(&repo->diff_drivers, NULL, reg);
147+
reg = git_atomic_compare_and_swap(&repo->diff_drivers, NULL, reg);
148148

149149
if (reg != NULL) /* if we race, free losing allocation */
150150
git_diff_driver_registry_free(reg);

src/index.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ static void index_free_deleted(git_index *index)
495495
return;
496496

497497
for (i = 0; i < index->deleted.length; ++i) {
498-
git_index_entry *ie = git__swap(index->deleted.contents[i], NULL);
498+
git_index_entry *ie = git_atomic_swap(index->deleted.contents[i], NULL);
499499
index_entry_free(ie);
500500
}
501501

@@ -2295,7 +2295,7 @@ int git_index_reuc_clear(git_index *index)
22952295
GIT_ASSERT_ARG(index);
22962296

22972297
for (i = 0; i < index->reuc.length; ++i)
2298-
index_entry_reuc_free(git__swap(index->reuc.contents[i], NULL));
2298+
index_entry_reuc_free(git_atomic_swap(index->reuc.contents[i], NULL));
22992299

23002300
git_vector_clear(&index->reuc);
23012301

@@ -3197,7 +3197,7 @@ int git_index_read_tree(git_index *index, const git_tree *tree)
31973197
/* well, this isn't good */;
31983198
} else {
31993199
git_vector_swap(&entries, &index->entries);
3200-
entries_map = git__swap(index->entries_map, entries_map);
3200+
entries_map = git_atomic_swap(index->entries_map, entries_map);
32013201
}
32023202

32033203
index->dirty = 1;
@@ -3331,7 +3331,7 @@ static int git_index_read_iterator(
33313331
goto done;
33323332

33333333
git_vector_swap(&new_entries, &index->entries);
3334-
new_entries_map = git__swap(index->entries_map, new_entries_map);
3334+
new_entries_map = git_atomic_swap(index->entries_map, new_entries_map);
33353335

33363336
git_vector_foreach(&remove_entries, i, entry) {
33373337
if (index->tree)

src/repository.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static void set_odb(git_repository *repo, git_odb *odb)
9393
GIT_REFCOUNT_INC(odb);
9494
}
9595

96-
if ((odb = git__swap(repo->_odb, odb)) != NULL) {
96+
if ((odb = git_atomic_swap(repo->_odb, odb)) != NULL) {
9797
GIT_REFCOUNT_OWN(odb, NULL);
9898
git_odb_free(odb);
9999
}
@@ -106,7 +106,7 @@ static void set_refdb(git_repository *repo, git_refdb *refdb)
106106
GIT_REFCOUNT_INC(refdb);
107107
}
108108

109-
if ((refdb = git__swap(repo->_refdb, refdb)) != NULL) {
109+
if ((refdb = git_atomic_swap(repo->_refdb, refdb)) != NULL) {
110110
GIT_REFCOUNT_OWN(refdb, NULL);
111111
git_refdb_free(refdb);
112112
}
@@ -119,7 +119,7 @@ static void set_config(git_repository *repo, git_config *config)
119119
GIT_REFCOUNT_INC(config);
120120
}
121121

122-
if ((config = git__swap(repo->_config, config)) != NULL) {
122+
if ((config = git_atomic_swap(repo->_config, config)) != NULL) {
123123
GIT_REFCOUNT_OWN(config, NULL);
124124
git_config_free(config);
125125
}
@@ -134,7 +134,7 @@ static void set_index(git_repository *repo, git_index *index)
134134
GIT_REFCOUNT_INC(index);
135135
}
136136

137-
if ((index = git__swap(repo->_index, index)) != NULL) {
137+
if ((index = git_atomic_swap(repo->_index, index)) != NULL) {
138138
GIT_REFCOUNT_OWN(index, NULL);
139139
git_index_free(index);
140140
}
@@ -1054,7 +1054,7 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
10541054
if (!error) {
10551055
GIT_REFCOUNT_OWN(config, repo);
10561056

1057-
config = git__compare_and_swap(&repo->_config, NULL, config);
1057+
config = git_atomic_compare_and_swap(&repo->_config, NULL, config);
10581058
if (config != NULL) {
10591059
GIT_REFCOUNT_OWN(config, NULL);
10601060
git_config_free(config);
@@ -1107,7 +1107,7 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
11071107
GIT_ASSERT_ARG(repo);
11081108
GIT_ASSERT_ARG(out);
11091109

1110-
*out = git__load(repo->_odb);
1110+
*out = git_atomic_load(repo->_odb);
11111111
if (*out == NULL) {
11121112
git_buf odb_path = GIT_BUF_INIT;
11131113
git_odb *odb;
@@ -1125,14 +1125,14 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
11251125
return error;
11261126
}
11271127

1128-
odb = git__compare_and_swap(&repo->_odb, NULL, odb);
1128+
odb = git_atomic_compare_and_swap(&repo->_odb, NULL, odb);
11291129
if (odb != NULL) {
11301130
GIT_REFCOUNT_OWN(odb, NULL);
11311131
git_odb_free(odb);
11321132
}
11331133

11341134
git_buf_dispose(&odb_path);
1135-
*out = git__load(repo->_odb);
1135+
*out = git_atomic_load(repo->_odb);
11361136
}
11371137

11381138
return error;
@@ -1170,7 +1170,7 @@ int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo)
11701170
if (!error) {
11711171
GIT_REFCOUNT_OWN(refdb, repo);
11721172

1173-
refdb = git__compare_and_swap(&repo->_refdb, NULL, refdb);
1173+
refdb = git_atomic_compare_and_swap(&repo->_refdb, NULL, refdb);
11741174
if (refdb != NULL) {
11751175
GIT_REFCOUNT_OWN(refdb, NULL);
11761176
git_refdb_free(refdb);
@@ -1218,7 +1218,7 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
12181218
if (!error) {
12191219
GIT_REFCOUNT_OWN(index, repo);
12201220

1221-
index = git__compare_and_swap(&repo->_index, NULL, index);
1221+
index = git_atomic_compare_and_swap(&repo->_index, NULL, index);
12221222
if (index != NULL) {
12231223
GIT_REFCOUNT_OWN(index, NULL);
12241224
git_index_free(index);
@@ -3044,8 +3044,8 @@ int git_repository_set_ident(git_repository *repo, const char *name, const char
30443044
GIT_ERROR_CHECK_ALLOC(tmp_email);
30453045
}
30463046

3047-
tmp_name = git__swap(repo->ident_name, tmp_name);
3048-
tmp_email = git__swap(repo->ident_email, tmp_email);
3047+
tmp_name = git_atomic_swap(repo->ident_name, tmp_name);
3048+
tmp_email = git_atomic_swap(repo->ident_email, tmp_email);
30493049

30503050
git__free(tmp_name);
30513051
git__free(tmp_email);

src/runtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static void shutdown_common(void)
3737
for (pos = git_atomic32_get(&shutdown_callback_count);
3838
pos > 0;
3939
pos = git_atomic32_dec(&shutdown_callback_count)) {
40-
cb = git__swap(shutdown_callback[pos - 1], NULL);
40+
cb = git_atomic_swap(shutdown_callback[pos - 1], NULL);
4141

4242
if (cb != NULL)
4343
cb();

src/thread-utils.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ GIT_INLINE(int) git_atomic32_get(git_atomic32 *a)
139139
#endif
140140
}
141141

142-
GIT_INLINE(void *) git___compare_and_swap(
142+
GIT_INLINE(void *) git_atomic__compare_and_swap(
143143
void * volatile *ptr, void *oldval, void *newval)
144144
{
145145
#if defined(GIT_WIN32)
@@ -158,7 +158,7 @@ GIT_INLINE(void *) git___compare_and_swap(
158158
#endif
159159
}
160160

161-
GIT_INLINE(volatile void *) git___swap(
161+
GIT_INLINE(volatile void *) git_atomic__swap(
162162
void * volatile *ptr, void *newval)
163163
{
164164
#if defined(GIT_WIN32)
@@ -174,7 +174,7 @@ GIT_INLINE(volatile void *) git___swap(
174174
#endif
175175
}
176176

177-
GIT_INLINE(volatile void *) git___load(void * volatile *ptr)
177+
GIT_INLINE(volatile void *) git_atomic__load(void * volatile *ptr)
178178
{
179179
#if defined(GIT_WIN32)
180180
void *newval = NULL, *oldval = NULL;
@@ -294,7 +294,7 @@ GIT_INLINE(int) git_atomic32_get(git_atomic32 *a)
294294
return (int)a->val;
295295
}
296296

297-
GIT_INLINE(void *) git___compare_and_swap(
297+
GIT_INLINE(void *) git_atomic__compare_and_swap(
298298
void * volatile *ptr, void *oldval, void *newval)
299299
{
300300
if (*ptr == oldval)
@@ -304,15 +304,15 @@ GIT_INLINE(void *) git___compare_and_swap(
304304
return oldval;
305305
}
306306

307-
GIT_INLINE(volatile void *) git___swap(
307+
GIT_INLINE(volatile void *) git_atomic__swap(
308308
void * volatile *ptr, void *newval)
309309
{
310310
volatile void *old = *ptr;
311311
*ptr = newval;
312312
return old;
313313
}
314314

315-
GIT_INLINE(volatile void *) git___load(void * volatile *ptr)
315+
GIT_INLINE(volatile void *) git_atomic__load(void * volatile *ptr)
316316
{
317317
return *ptr;
318318
}
@@ -342,12 +342,14 @@ GIT_INLINE(int64_t) git_atomic64_get(git_atomic64 *a)
342342
/* Atomically replace oldval with newval
343343
* @return oldval if it was replaced or newval if it was not
344344
*/
345-
#define git__compare_and_swap(P,O,N) \
346-
git___compare_and_swap((void * volatile *)P, O, N)
345+
#define git_atomic_compare_and_swap(P,O,N) \
346+
git_atomic__compare_and_swap((void * volatile *)P, O, N)
347347

348-
#define git__swap(ptr, val) (void *)git___swap((void * volatile *)&ptr, val)
348+
#define git_atomic_swap(ptr, val) \
349+
(void *)git_atomic__swap((void * volatile *)&ptr, val)
349350

350-
#define git__load(ptr) (void *)git___load((void * volatile *)&ptr)
351+
#define git_atomic_load(ptr) \
352+
(void *)git_atomic__load((void * volatile *)&ptr)
351353

352354
#if defined(GIT_THREADS)
353355

src/util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ typedef void (*git_refcount_freeptr)(void *r);
186186
}
187187

188188
#define GIT_REFCOUNT_OWN(r, o) { \
189-
(void)git__swap((r)->rc.owner, o); \
189+
(void)git_atomic_swap((r)->rc.owner, o); \
190190
}
191191

192-
#define GIT_REFCOUNT_OWNER(r) git__load((r)->rc.owner)
192+
#define GIT_REFCOUNT_OWNER(r) git_atomic_load((r)->rc.owner)
193193

194194
#define GIT_REFCOUNT_VAL(r) git_atomic32_get((r)->rc.refcount)
195195

0 commit comments

Comments
 (0)