threads: give atomic functions the git_atomic prefix
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
diff --git a/src/attrcache.c b/src/attrcache.c
index 47fb675..2485b05 100644
--- a/src/attrcache.c
+++ b/src/attrcache.c
@@ -108,7 +108,7 @@ static int attr_cache_upsert(git_attr_cache *cache, git_attr_file *file)
* Replace the existing value if another thread has
* created it in the meantime.
*/
- old = git__swap(entry->file[file->source], file);
+ old = git_atomic_swap(entry->file[file->source], file);
if (old) {
GIT_REFCOUNT_OWN(old, NULL);
@@ -132,7 +132,7 @@ static int attr_cache_remove(git_attr_cache *cache, git_attr_file *file)
return error;
if ((entry = attr_cache_lookup_entry(cache, file->entry->path)) != NULL)
- old = git__compare_and_swap(&entry->file[file->source], file, NULL);
+ old = git_atomic_compare_and_swap(&entry->file[file->source], file, NULL);
attr_cache_unlock(cache);
@@ -321,7 +321,7 @@ static void attr_cache__free(git_attr_cache *cache)
git_strmap_foreach_value(cache->files, entry, {
for (i = 0; i < GIT_ATTR_FILE_NUM_SOURCES; ++i) {
- if ((file = git__swap(entry->file[i], NULL)) != NULL) {
+ if ((file = git_atomic_swap(entry->file[i], NULL)) != NULL) {
GIT_REFCOUNT_OWN(file, NULL);
git_attr_file__free(file);
}
@@ -395,7 +395,7 @@ int git_attr_cache__init(git_repository *repo)
(ret = git_pool_init(&cache->pool, 1)) < 0)
goto cancel;
- cache = git__compare_and_swap(&repo->attrcache, NULL, cache);
+ cache = git_atomic_compare_and_swap(&repo->attrcache, NULL, cache);
if (cache)
goto cancel; /* raced with another thread, free this but no error */
@@ -417,7 +417,7 @@ int git_attr_cache_flush(git_repository *repo)
/* this could be done less expensively, but for now, we'll just free
* the entire attrcache and let the next use reinitialize it...
*/
- if (repo && (cache = git__swap(repo->attrcache, NULL)) != NULL)
+ if (repo && (cache = git_atomic_swap(repo->attrcache, NULL)) != NULL)
attr_cache__free(cache);
return 0;
diff --git a/src/config_cache.c b/src/config_cache.c
index 1a28ba9..2f0455a 100644
--- a/src/config_cache.c
+++ b/src/config_cache.c
@@ -111,7 +111,7 @@ int git_config__configmap_lookup(int *out, git_config *config, git_configmap_ite
int git_repository__configmap_lookup(int *out, git_repository *repo, git_configmap_item item)
{
- *out = (int)(intptr_t)git__load(repo->configmap_cache[(int)item]);
+ *out = (int)(intptr_t)git_atomic_load(repo->configmap_cache[(int)item]);
if (*out == GIT_CONFIGMAP_NOT_CACHED) {
int error;
@@ -122,7 +122,7 @@ int git_repository__configmap_lookup(int *out, git_repository *repo, git_configm
(error = git_config__configmap_lookup(out, config, item)) < 0)
return error;
- git__compare_and_swap(&repo->configmap_cache[(int)item], &oldval, out);
+ git_atomic_compare_and_swap(&repo->configmap_cache[(int)item], &oldval, out);
}
return 0;
diff --git a/src/diff_driver.c b/src/diff_driver.c
index 606c391..6b19012 100644
--- a/src/diff_driver.c
+++ b/src/diff_driver.c
@@ -144,7 +144,7 @@ static git_diff_driver_registry *git_repository_driver_registry(
{
if (!repo->diff_drivers) {
git_diff_driver_registry *reg = git_diff_driver_registry_new();
- reg = git__compare_and_swap(&repo->diff_drivers, NULL, reg);
+ reg = git_atomic_compare_and_swap(&repo->diff_drivers, NULL, reg);
if (reg != NULL) /* if we race, free losing allocation */
git_diff_driver_registry_free(reg);
diff --git a/src/index.c b/src/index.c
index 942fcca..7ebe075 100644
--- a/src/index.c
+++ b/src/index.c
@@ -495,7 +495,7 @@ static void index_free_deleted(git_index *index)
return;
for (i = 0; i < index->deleted.length; ++i) {
- git_index_entry *ie = git__swap(index->deleted.contents[i], NULL);
+ git_index_entry *ie = git_atomic_swap(index->deleted.contents[i], NULL);
index_entry_free(ie);
}
@@ -2295,7 +2295,7 @@ int git_index_reuc_clear(git_index *index)
GIT_ASSERT_ARG(index);
for (i = 0; i < index->reuc.length; ++i)
- index_entry_reuc_free(git__swap(index->reuc.contents[i], NULL));
+ index_entry_reuc_free(git_atomic_swap(index->reuc.contents[i], NULL));
git_vector_clear(&index->reuc);
@@ -3197,7 +3197,7 @@ int git_index_read_tree(git_index *index, const git_tree *tree)
/* well, this isn't good */;
} else {
git_vector_swap(&entries, &index->entries);
- entries_map = git__swap(index->entries_map, entries_map);
+ entries_map = git_atomic_swap(index->entries_map, entries_map);
}
index->dirty = 1;
@@ -3331,7 +3331,7 @@ static int git_index_read_iterator(
goto done;
git_vector_swap(&new_entries, &index->entries);
- new_entries_map = git__swap(index->entries_map, new_entries_map);
+ new_entries_map = git_atomic_swap(index->entries_map, new_entries_map);
git_vector_foreach(&remove_entries, i, entry) {
if (index->tree)
diff --git a/src/repository.c b/src/repository.c
index bef84ca..3b6bcbe 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -93,7 +93,7 @@ static void set_odb(git_repository *repo, git_odb *odb)
GIT_REFCOUNT_INC(odb);
}
- if ((odb = git__swap(repo->_odb, odb)) != NULL) {
+ if ((odb = git_atomic_swap(repo->_odb, odb)) != NULL) {
GIT_REFCOUNT_OWN(odb, NULL);
git_odb_free(odb);
}
@@ -106,7 +106,7 @@ static void set_refdb(git_repository *repo, git_refdb *refdb)
GIT_REFCOUNT_INC(refdb);
}
- if ((refdb = git__swap(repo->_refdb, refdb)) != NULL) {
+ if ((refdb = git_atomic_swap(repo->_refdb, refdb)) != NULL) {
GIT_REFCOUNT_OWN(refdb, NULL);
git_refdb_free(refdb);
}
@@ -119,7 +119,7 @@ static void set_config(git_repository *repo, git_config *config)
GIT_REFCOUNT_INC(config);
}
- if ((config = git__swap(repo->_config, config)) != NULL) {
+ if ((config = git_atomic_swap(repo->_config, config)) != NULL) {
GIT_REFCOUNT_OWN(config, NULL);
git_config_free(config);
}
@@ -134,7 +134,7 @@ static void set_index(git_repository *repo, git_index *index)
GIT_REFCOUNT_INC(index);
}
- if ((index = git__swap(repo->_index, index)) != NULL) {
+ if ((index = git_atomic_swap(repo->_index, index)) != NULL) {
GIT_REFCOUNT_OWN(index, NULL);
git_index_free(index);
}
@@ -1054,7 +1054,7 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
if (!error) {
GIT_REFCOUNT_OWN(config, repo);
- config = git__compare_and_swap(&repo->_config, NULL, config);
+ config = git_atomic_compare_and_swap(&repo->_config, NULL, config);
if (config != NULL) {
GIT_REFCOUNT_OWN(config, NULL);
git_config_free(config);
@@ -1107,7 +1107,7 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
GIT_ASSERT_ARG(repo);
GIT_ASSERT_ARG(out);
- *out = git__load(repo->_odb);
+ *out = git_atomic_load(repo->_odb);
if (*out == NULL) {
git_buf odb_path = GIT_BUF_INIT;
git_odb *odb;
@@ -1125,14 +1125,14 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
return error;
}
- odb = git__compare_and_swap(&repo->_odb, NULL, odb);
+ odb = git_atomic_compare_and_swap(&repo->_odb, NULL, odb);
if (odb != NULL) {
GIT_REFCOUNT_OWN(odb, NULL);
git_odb_free(odb);
}
git_buf_dispose(&odb_path);
- *out = git__load(repo->_odb);
+ *out = git_atomic_load(repo->_odb);
}
return error;
@@ -1170,7 +1170,7 @@ int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo)
if (!error) {
GIT_REFCOUNT_OWN(refdb, repo);
- refdb = git__compare_and_swap(&repo->_refdb, NULL, refdb);
+ refdb = git_atomic_compare_and_swap(&repo->_refdb, NULL, refdb);
if (refdb != NULL) {
GIT_REFCOUNT_OWN(refdb, NULL);
git_refdb_free(refdb);
@@ -1218,7 +1218,7 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
if (!error) {
GIT_REFCOUNT_OWN(index, repo);
- index = git__compare_and_swap(&repo->_index, NULL, index);
+ index = git_atomic_compare_and_swap(&repo->_index, NULL, index);
if (index != NULL) {
GIT_REFCOUNT_OWN(index, NULL);
git_index_free(index);
@@ -3044,8 +3044,8 @@ int git_repository_set_ident(git_repository *repo, const char *name, const char
GIT_ERROR_CHECK_ALLOC(tmp_email);
}
- tmp_name = git__swap(repo->ident_name, tmp_name);
- tmp_email = git__swap(repo->ident_email, tmp_email);
+ tmp_name = git_atomic_swap(repo->ident_name, tmp_name);
+ tmp_email = git_atomic_swap(repo->ident_email, tmp_email);
git__free(tmp_name);
git__free(tmp_email);
diff --git a/src/runtime.c b/src/runtime.c
index 3fd0649..b61c3c4 100644
--- a/src/runtime.c
+++ b/src/runtime.c
@@ -37,7 +37,7 @@ static void shutdown_common(void)
for (pos = git_atomic32_get(&shutdown_callback_count);
pos > 0;
pos = git_atomic32_dec(&shutdown_callback_count)) {
- cb = git__swap(shutdown_callback[pos - 1], NULL);
+ cb = git_atomic_swap(shutdown_callback[pos - 1], NULL);
if (cb != NULL)
cb();
diff --git a/src/thread-utils.h b/src/thread-utils.h
index 31a4c09..9b511b6 100644
--- a/src/thread-utils.h
+++ b/src/thread-utils.h
@@ -139,7 +139,7 @@ GIT_INLINE(int) git_atomic32_get(git_atomic32 *a)
#endif
}
-GIT_INLINE(void *) git___compare_and_swap(
+GIT_INLINE(void *) git_atomic__compare_and_swap(
void * volatile *ptr, void *oldval, void *newval)
{
#if defined(GIT_WIN32)
@@ -158,7 +158,7 @@ GIT_INLINE(void *) git___compare_and_swap(
#endif
}
-GIT_INLINE(volatile void *) git___swap(
+GIT_INLINE(volatile void *) git_atomic__swap(
void * volatile *ptr, void *newval)
{
#if defined(GIT_WIN32)
@@ -174,7 +174,7 @@ GIT_INLINE(volatile void *) git___swap(
#endif
}
-GIT_INLINE(volatile void *) git___load(void * volatile *ptr)
+GIT_INLINE(volatile void *) git_atomic__load(void * volatile *ptr)
{
#if defined(GIT_WIN32)
void *newval = NULL, *oldval = NULL;
@@ -294,7 +294,7 @@ GIT_INLINE(int) git_atomic32_get(git_atomic32 *a)
return (int)a->val;
}
-GIT_INLINE(void *) git___compare_and_swap(
+GIT_INLINE(void *) git_atomic__compare_and_swap(
void * volatile *ptr, void *oldval, void *newval)
{
if (*ptr == oldval)
@@ -304,7 +304,7 @@ GIT_INLINE(void *) git___compare_and_swap(
return oldval;
}
-GIT_INLINE(volatile void *) git___swap(
+GIT_INLINE(volatile void *) git_atomic__swap(
void * volatile *ptr, void *newval)
{
volatile void *old = *ptr;
@@ -312,7 +312,7 @@ GIT_INLINE(volatile void *) git___swap(
return old;
}
-GIT_INLINE(volatile void *) git___load(void * volatile *ptr)
+GIT_INLINE(volatile void *) git_atomic__load(void * volatile *ptr)
{
return *ptr;
}
@@ -342,12 +342,14 @@ GIT_INLINE(int64_t) git_atomic64_get(git_atomic64 *a)
/* Atomically replace oldval with newval
* @return oldval if it was replaced or newval if it was not
*/
-#define git__compare_and_swap(P,O,N) \
- git___compare_and_swap((void * volatile *)P, O, N)
+#define git_atomic_compare_and_swap(P,O,N) \
+ git_atomic__compare_and_swap((void * volatile *)P, O, N)
-#define git__swap(ptr, val) (void *)git___swap((void * volatile *)&ptr, val)
+#define git_atomic_swap(ptr, val) \
+ (void *)git_atomic__swap((void * volatile *)&ptr, val)
-#define git__load(ptr) (void *)git___load((void * volatile *)&ptr)
+#define git_atomic_load(ptr) \
+ (void *)git_atomic__load((void * volatile *)&ptr)
#if defined(GIT_THREADS)
diff --git a/src/util.h b/src/util.h
index 6c7c4c2..b8ea68c 100644
--- a/src/util.h
+++ b/src/util.h
@@ -186,10 +186,10 @@ typedef void (*git_refcount_freeptr)(void *r);
}
#define GIT_REFCOUNT_OWN(r, o) { \
- (void)git__swap((r)->rc.owner, o); \
+ (void)git_atomic_swap((r)->rc.owner, o); \
}
-#define GIT_REFCOUNT_OWNER(r) git__load((r)->rc.owner)
+#define GIT_REFCOUNT_OWNER(r) git_atomic_load((r)->rc.owner)
#define GIT_REFCOUNT_VAL(r) git_atomic32_get((r)->rc.refcount)