Skip to content

Commit 37763d3

Browse files
committed
threads: rename git_atomic to git_atomic32
Clarify the `git_atomic` type and functions now that we have a 64 bit version as well (`git_atomic64`).
1 parent 9800728 commit 37763d3

File tree

17 files changed

+68
-68
lines changed

17 files changed

+68
-68
lines changed

src/attr_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ int git_attr_session__init(git_attr_session *session, git_repository *repo)
960960
GIT_ASSERT_ARG(repo);
961961

962962
memset(session, 0, sizeof(*session));
963-
session->key = git_atomic_inc(&repo->attr_session_key);
963+
session->key = git_atomic32_inc(&repo->attr_session_key);
964964

965965
return 0;
966966
}

src/cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ void git_cached_obj_decref(void *_obj)
235235
{
236236
git_cached_obj *obj = _obj;
237237

238-
if (git_atomic_dec(&obj->refcount) == 0) {
238+
if (git_atomic32_dec(&obj->refcount) == 0) {
239239
switch (obj->flags) {
240240
case GIT_CACHE_STORE_RAW:
241241
git_odb_object__free(_obj);

src/cache.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ enum {
2323
};
2424

2525
typedef struct {
26-
git_oid oid;
27-
int16_t type; /* git_object_t value */
28-
uint16_t flags; /* GIT_CACHE_STORE value */
29-
size_t size;
30-
git_atomic refcount;
26+
git_oid oid;
27+
int16_t type; /* git_object_t value */
28+
uint16_t flags; /* GIT_CACHE_STORE value */
29+
size_t size;
30+
git_atomic32 refcount;
3131
} git_cached_obj;
3232

3333
typedef struct {
@@ -61,7 +61,7 @@ GIT_INLINE(size_t) git_cache_size(git_cache *cache)
6161
GIT_INLINE(void) git_cached_obj_incref(void *_obj)
6262
{
6363
git_cached_obj *obj = _obj;
64-
git_atomic_inc(&obj->refcount);
64+
git_atomic32_inc(&obj->refcount);
6565
}
6666

6767
void git_cached_obj_decref(void *_obj);

src/index.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ static void index_free(git_index *index)
461461
/* index iterators increment the refcount of the index, so if we
462462
* get here then there should be no outstanding iterators.
463463
*/
464-
if (git_atomic_get(&index->readers))
464+
if (git_atomic32_get(&index->readers))
465465
return;
466466

467467
git_index_clear(index);
@@ -488,7 +488,7 @@ void git_index_free(git_index *index)
488488
/* call with locked index */
489489
static void index_free_deleted(git_index *index)
490490
{
491-
int readers = (int)git_atomic_get(&index->readers);
491+
int readers = (int)git_atomic32_get(&index->readers);
492492
size_t i;
493493

494494
if (readers > 0 || !index->deleted.length)
@@ -516,7 +516,7 @@ static int index_remove_entry(git_index *index, size_t pos)
516516
error = git_vector_remove(&index->entries, pos);
517517

518518
if (!error) {
519-
if (git_atomic_get(&index->readers) > 0) {
519+
if (git_atomic32_get(&index->readers) > 0) {
520520
error = git_vector_insert(&index->deleted, entry);
521521
} else {
522522
index_entry_free(entry);
@@ -3637,7 +3637,7 @@ int git_index_snapshot_new(git_vector *snap, git_index *index)
36373637

36383638
GIT_REFCOUNT_INC(index);
36393639

3640-
git_atomic_inc(&index->readers);
3640+
git_atomic32_inc(&index->readers);
36413641
git_vector_sort(&index->entries);
36423642

36433643
error = git_vector_dup(snap, &index->entries, index->entries._cmp);
@@ -3652,7 +3652,7 @@ void git_index_snapshot_release(git_vector *snap, git_index *index)
36523652
{
36533653
git_vector_free(snap);
36543654

3655-
git_atomic_dec(&index->readers);
3655+
git_atomic32_dec(&index->readers);
36563656

36573657
git_index_free(index);
36583658
}

src/index.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct git_index {
3333
git_idxmap *entries_map;
3434

3535
git_vector deleted; /* deleted entries if readers > 0 */
36-
git_atomic readers; /* number of active iterators */
36+
git_atomic32 readers; /* number of active iterators */
3737

3838
unsigned int on_disk:1;
3939
unsigned int ignore_case:1;

src/mwindow.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
7979
git__free(packname);
8080

8181
if (pack != NULL) {
82-
git_atomic_inc(&pack->refcount);
82+
git_atomic32_inc(&pack->refcount);
8383
git_mutex_unlock(&git__mwindow_mutex);
8484
*out = pack;
8585
return 0;
@@ -91,7 +91,7 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
9191
return error;
9292
}
9393

94-
git_atomic_inc(&pack->refcount);
94+
git_atomic32_inc(&pack->refcount);
9595

9696
error = git_strmap_set(git__pack_cache, pack->pack_name, pack);
9797
git_mutex_unlock(&git__mwindow_mutex);
@@ -118,7 +118,7 @@ int git_mwindow_put_pack(struct git_pack_file *pack)
118118
/* if we cannot find it, the state is corrupted */
119119
GIT_ASSERT(git_strmap_exists(git__pack_cache, pack->pack_name));
120120

121-
count = git_atomic_dec(&pack->refcount);
121+
count = git_atomic32_dec(&pack->refcount);
122122
if (count == 0) {
123123
git_strmap_delete(git__pack_cache, pack->pack_name);
124124
pack_to_delete = pack;

src/pack.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static git_pack_cache_entry *new_cache_object(git_rawobj *source)
5757
if (!e)
5858
return NULL;
5959

60-
git_atomic_inc(&e->refcount);
60+
git_atomic32_inc(&e->refcount);
6161
memcpy(&e->raw, source, sizeof(git_rawobj));
6262

6363
return e;
@@ -114,7 +114,7 @@ static git_pack_cache_entry *cache_get(git_pack_cache *cache, off64_t offset)
114114
return NULL;
115115

116116
if ((entry = git_offmap_get(cache->entries, offset)) != NULL) {
117-
git_atomic_inc(&entry->refcount);
117+
git_atomic32_inc(&entry->refcount);
118118
entry->last_usage = cache->use_ctr++;
119119
}
120120
git_mutex_unlock(&cache->lock);
@@ -129,7 +129,7 @@ static void free_lowest_entry(git_pack_cache *cache)
129129
git_pack_cache_entry *entry;
130130

131131
git_offmap_foreach(cache->entries, offset, entry, {
132-
if (entry && git_atomic_get(&entry->refcount) == 0) {
132+
if (entry && git_atomic32_get(&entry->refcount) == 0) {
133133
cache->memory_used -= entry->raw.len;
134134
git_offmap_delete(cache->entries, offset);
135135
free_cache_object(entry);
@@ -759,7 +759,7 @@ int git_packfile_unpack(
759759
GIT_ERROR_CHECK_ALLOC(obj->data);
760760

761761
memcpy(obj->data, data, obj->len + 1);
762-
git_atomic_dec(&cached->refcount);
762+
git_atomic32_dec(&cached->refcount);
763763
goto cleanup;
764764
}
765765

@@ -807,7 +807,7 @@ int git_packfile_unpack(
807807
}
808808

809809
if (cached) {
810-
git_atomic_dec(&cached->refcount);
810+
git_atomic32_dec(&cached->refcount);
811811
cached = NULL;
812812
}
813813

@@ -821,7 +821,7 @@ int git_packfile_unpack(
821821
if (error < 0) {
822822
git__free(obj->data);
823823
if (cached)
824-
git_atomic_dec(&cached->refcount);
824+
git_atomic32_dec(&cached->refcount);
825825
}
826826

827827
if (elem)

src/pack.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct git_pack_idx_header {
5858

5959
typedef struct git_pack_cache_entry {
6060
size_t last_usage; /* enough? */
61-
git_atomic refcount;
61+
git_atomic32 refcount;
6262
git_rawobj raw;
6363
} git_pack_cache_entry;
6464

@@ -86,7 +86,7 @@ struct git_pack_file {
8686
git_mwindow_file mwf;
8787
git_map index_map;
8888
git_mutex lock; /* protect updates to index_map */
89-
git_atomic refcount;
89+
git_atomic32 refcount;
9090

9191
uint32_t num_objects;
9292
uint32_t num_bad_objects;

src/repository.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ struct git_repository {
152152

153153
unsigned int lru_counter;
154154

155-
git_atomic attr_session_key;
155+
git_atomic32 attr_session_key;
156156

157157
git_configmap_value configmap_cache[GIT_CONFIGMAP_CACHE_MAX];
158158
git_strmap *submodule_cache;

src/runtime.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#include "runtime.h"
1010

1111
static git_runtime_shutdown_fn shutdown_callback[32];
12-
static git_atomic shutdown_callback_count;
12+
static git_atomic32 shutdown_callback_count;
1313

14-
static git_atomic init_count;
14+
static git_atomic32 init_count;
1515

1616
static int init_common(git_runtime_init_fn init_fns[], size_t cnt)
1717
{
@@ -34,9 +34,9 @@ static void shutdown_common(void)
3434
git_runtime_shutdown_fn cb;
3535
int pos;
3636

37-
for (pos = git_atomic_get(&shutdown_callback_count);
37+
for (pos = git_atomic32_get(&shutdown_callback_count);
3838
pos > 0;
39-
pos = git_atomic_dec(&shutdown_callback_count)) {
39+
pos = git_atomic32_dec(&shutdown_callback_count)) {
4040
cb = git__swap(shutdown_callback[pos - 1], NULL);
4141

4242
if (cb != NULL)
@@ -46,12 +46,12 @@ static void shutdown_common(void)
4646

4747
int git_runtime_shutdown_register(git_runtime_shutdown_fn callback)
4848
{
49-
int count = git_atomic_inc(&shutdown_callback_count);
49+
int count = git_atomic32_inc(&shutdown_callback_count);
5050

5151
if (count > (int)ARRAY_SIZE(shutdown_callback) || count == 0) {
5252
git_error_set(GIT_ERROR_INVALID,
5353
"too many shutdown callbacks registered");
54-
git_atomic_dec(&shutdown_callback_count);
54+
git_atomic32_dec(&shutdown_callback_count);
5555
return -1;
5656
}
5757

@@ -116,7 +116,7 @@ int git_runtime_init(git_runtime_init_fn init_fns[], size_t cnt)
116116
return -1;
117117

118118
/* Only do work on a 0 -> 1 transition of the refcount */
119-
if ((ret = git_atomic_inc(&init_count)) == 1) {
119+
if ((ret = git_atomic32_inc(&init_count)) == 1) {
120120
if (init_common(init_fns, cnt) < 0)
121121
ret = -1;
122122
}
@@ -136,7 +136,7 @@ int git_runtime_shutdown(void)
136136
return -1;
137137

138138
/* Only do work on a 1 -> 0 transition of the refcount */
139-
if ((ret = git_atomic_dec(&init_count)) == 0)
139+
if ((ret = git_atomic32_dec(&init_count)) == 0)
140140
shutdown_common();
141141

142142
/* Exit the lock */

0 commit comments

Comments
 (0)