summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2020-12-05 15:26:59 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2020-12-06 01:08:22 +0000
commit37763d38fbf5db932be8d6a0070255839e7719ca (patch)
tree4eee46a0f689872fc4b8440e91ff82ec0ee3b154
parent9800728a746b872fdd22db9e68bc85ef0c851f27 (diff)
downloadlibgit2-37763d38fbf5db932be8d6a0070255839e7719ca.tar.gz
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`).
-rw-r--r--src/attr_file.c2
-rw-r--r--src/cache.c2
-rw-r--r--src/cache.h12
-rw-r--r--src/index.c10
-rw-r--r--src/index.h2
-rw-r--r--src/mwindow.c6
-rw-r--r--src/pack.c12
-rw-r--r--src/pack.h4
-rw-r--r--src/repository.h2
-rw-r--r--src/runtime.c16
-rw-r--r--src/thread-utils.h30
-rw-r--r--src/transports/local.c4
-rw-r--r--src/transports/smart.c4
-rw-r--r--src/transports/smart.h2
-rw-r--r--src/transports/smart_protocol.c2
-rw-r--r--src/util.h8
-rw-r--r--tests/threads/diff.c18
17 files changed, 68 insertions, 68 deletions
diff --git a/src/attr_file.c b/src/attr_file.c
index 0781c1d61..adc56d53e 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -960,7 +960,7 @@ int git_attr_session__init(git_attr_session *session, git_repository *repo)
GIT_ASSERT_ARG(repo);
memset(session, 0, sizeof(*session));
- session->key = git_atomic_inc(&repo->attr_session_key);
+ session->key = git_atomic32_inc(&repo->attr_session_key);
return 0;
}
diff --git a/src/cache.c b/src/cache.c
index a76da50d7..dbd4c319a 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -235,7 +235,7 @@ void git_cached_obj_decref(void *_obj)
{
git_cached_obj *obj = _obj;
- if (git_atomic_dec(&obj->refcount) == 0) {
+ if (git_atomic32_dec(&obj->refcount) == 0) {
switch (obj->flags) {
case GIT_CACHE_STORE_RAW:
git_odb_object__free(_obj);
diff --git a/src/cache.h b/src/cache.h
index 1e6179236..c43422d6f 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -23,11 +23,11 @@ enum {
};
typedef struct {
- git_oid oid;
- int16_t type; /* git_object_t value */
- uint16_t flags; /* GIT_CACHE_STORE value */
- size_t size;
- git_atomic refcount;
+ git_oid oid;
+ int16_t type; /* git_object_t value */
+ uint16_t flags; /* GIT_CACHE_STORE value */
+ size_t size;
+ git_atomic32 refcount;
} git_cached_obj;
typedef struct {
@@ -61,7 +61,7 @@ GIT_INLINE(size_t) git_cache_size(git_cache *cache)
GIT_INLINE(void) git_cached_obj_incref(void *_obj)
{
git_cached_obj *obj = _obj;
- git_atomic_inc(&obj->refcount);
+ git_atomic32_inc(&obj->refcount);
}
void git_cached_obj_decref(void *_obj);
diff --git a/src/index.c b/src/index.c
index d9116c412..942fcca26 100644
--- a/src/index.c
+++ b/src/index.c
@@ -461,7 +461,7 @@ static void index_free(git_index *index)
/* index iterators increment the refcount of the index, so if we
* get here then there should be no outstanding iterators.
*/
- if (git_atomic_get(&index->readers))
+ if (git_atomic32_get(&index->readers))
return;
git_index_clear(index);
@@ -488,7 +488,7 @@ void git_index_free(git_index *index)
/* call with locked index */
static void index_free_deleted(git_index *index)
{
- int readers = (int)git_atomic_get(&index->readers);
+ int readers = (int)git_atomic32_get(&index->readers);
size_t i;
if (readers > 0 || !index->deleted.length)
@@ -516,7 +516,7 @@ static int index_remove_entry(git_index *index, size_t pos)
error = git_vector_remove(&index->entries, pos);
if (!error) {
- if (git_atomic_get(&index->readers) > 0) {
+ if (git_atomic32_get(&index->readers) > 0) {
error = git_vector_insert(&index->deleted, entry);
} else {
index_entry_free(entry);
@@ -3637,7 +3637,7 @@ int git_index_snapshot_new(git_vector *snap, git_index *index)
GIT_REFCOUNT_INC(index);
- git_atomic_inc(&index->readers);
+ git_atomic32_inc(&index->readers);
git_vector_sort(&index->entries);
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)
{
git_vector_free(snap);
- git_atomic_dec(&index->readers);
+ git_atomic32_dec(&index->readers);
git_index_free(index);
}
diff --git a/src/index.h b/src/index.h
index 54402f563..a365867d0 100644
--- a/src/index.h
+++ b/src/index.h
@@ -33,7 +33,7 @@ struct git_index {
git_idxmap *entries_map;
git_vector deleted; /* deleted entries if readers > 0 */
- git_atomic readers; /* number of active iterators */
+ git_atomic32 readers; /* number of active iterators */
unsigned int on_disk:1;
unsigned int ignore_case:1;
diff --git a/src/mwindow.c b/src/mwindow.c
index 4f105e659..7832d9c8b 100644
--- a/src/mwindow.c
+++ b/src/mwindow.c
@@ -79,7 +79,7 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
git__free(packname);
if (pack != NULL) {
- git_atomic_inc(&pack->refcount);
+ git_atomic32_inc(&pack->refcount);
git_mutex_unlock(&git__mwindow_mutex);
*out = pack;
return 0;
@@ -91,7 +91,7 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
return error;
}
- git_atomic_inc(&pack->refcount);
+ git_atomic32_inc(&pack->refcount);
error = git_strmap_set(git__pack_cache, pack->pack_name, pack);
git_mutex_unlock(&git__mwindow_mutex);
@@ -118,7 +118,7 @@ int git_mwindow_put_pack(struct git_pack_file *pack)
/* if we cannot find it, the state is corrupted */
GIT_ASSERT(git_strmap_exists(git__pack_cache, pack->pack_name));
- count = git_atomic_dec(&pack->refcount);
+ count = git_atomic32_dec(&pack->refcount);
if (count == 0) {
git_strmap_delete(git__pack_cache, pack->pack_name);
pack_to_delete = pack;
diff --git a/src/pack.c b/src/pack.c
index b88c52acf..a9140c63d 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -57,7 +57,7 @@ static git_pack_cache_entry *new_cache_object(git_rawobj *source)
if (!e)
return NULL;
- git_atomic_inc(&e->refcount);
+ git_atomic32_inc(&e->refcount);
memcpy(&e->raw, source, sizeof(git_rawobj));
return e;
@@ -114,7 +114,7 @@ static git_pack_cache_entry *cache_get(git_pack_cache *cache, off64_t offset)
return NULL;
if ((entry = git_offmap_get(cache->entries, offset)) != NULL) {
- git_atomic_inc(&entry->refcount);
+ git_atomic32_inc(&entry->refcount);
entry->last_usage = cache->use_ctr++;
}
git_mutex_unlock(&cache->lock);
@@ -129,7 +129,7 @@ static void free_lowest_entry(git_pack_cache *cache)
git_pack_cache_entry *entry;
git_offmap_foreach(cache->entries, offset, entry, {
- if (entry && git_atomic_get(&entry->refcount) == 0) {
+ if (entry && git_atomic32_get(&entry->refcount) == 0) {
cache->memory_used -= entry->raw.len;
git_offmap_delete(cache->entries, offset);
free_cache_object(entry);
@@ -759,7 +759,7 @@ int git_packfile_unpack(
GIT_ERROR_CHECK_ALLOC(obj->data);
memcpy(obj->data, data, obj->len + 1);
- git_atomic_dec(&cached->refcount);
+ git_atomic32_dec(&cached->refcount);
goto cleanup;
}
@@ -807,7 +807,7 @@ int git_packfile_unpack(
}
if (cached) {
- git_atomic_dec(&cached->refcount);
+ git_atomic32_dec(&cached->refcount);
cached = NULL;
}
@@ -821,7 +821,7 @@ cleanup:
if (error < 0) {
git__free(obj->data);
if (cached)
- git_atomic_dec(&cached->refcount);
+ git_atomic32_dec(&cached->refcount);
}
if (elem)
diff --git a/src/pack.h b/src/pack.h
index 7c3be079e..1d077240d 100644
--- a/src/pack.h
+++ b/src/pack.h
@@ -58,7 +58,7 @@ struct git_pack_idx_header {
typedef struct git_pack_cache_entry {
size_t last_usage; /* enough? */
- git_atomic refcount;
+ git_atomic32 refcount;
git_rawobj raw;
} git_pack_cache_entry;
@@ -86,7 +86,7 @@ struct git_pack_file {
git_mwindow_file mwf;
git_map index_map;
git_mutex lock; /* protect updates to index_map */
- git_atomic refcount;
+ git_atomic32 refcount;
uint32_t num_objects;
uint32_t num_bad_objects;
diff --git a/src/repository.h b/src/repository.h
index de009ba5e..4b1222e3a 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -152,7 +152,7 @@ struct git_repository {
unsigned int lru_counter;
- git_atomic attr_session_key;
+ git_atomic32 attr_session_key;
git_configmap_value configmap_cache[GIT_CONFIGMAP_CACHE_MAX];
git_strmap *submodule_cache;
diff --git a/src/runtime.c b/src/runtime.c
index a214b435e..3fd064982 100644
--- a/src/runtime.c
+++ b/src/runtime.c
@@ -9,9 +9,9 @@
#include "runtime.h"
static git_runtime_shutdown_fn shutdown_callback[32];
-static git_atomic shutdown_callback_count;
+static git_atomic32 shutdown_callback_count;
-static git_atomic init_count;
+static git_atomic32 init_count;
static int init_common(git_runtime_init_fn init_fns[], size_t cnt)
{
@@ -34,9 +34,9 @@ static void shutdown_common(void)
git_runtime_shutdown_fn cb;
int pos;
- for (pos = git_atomic_get(&shutdown_callback_count);
+ for (pos = git_atomic32_get(&shutdown_callback_count);
pos > 0;
- pos = git_atomic_dec(&shutdown_callback_count)) {
+ pos = git_atomic32_dec(&shutdown_callback_count)) {
cb = git__swap(shutdown_callback[pos - 1], NULL);
if (cb != NULL)
@@ -46,12 +46,12 @@ static void shutdown_common(void)
int git_runtime_shutdown_register(git_runtime_shutdown_fn callback)
{
- int count = git_atomic_inc(&shutdown_callback_count);
+ int count = git_atomic32_inc(&shutdown_callback_count);
if (count > (int)ARRAY_SIZE(shutdown_callback) || count == 0) {
git_error_set(GIT_ERROR_INVALID,
"too many shutdown callbacks registered");
- git_atomic_dec(&shutdown_callback_count);
+ git_atomic32_dec(&shutdown_callback_count);
return -1;
}
@@ -116,7 +116,7 @@ int git_runtime_init(git_runtime_init_fn init_fns[], size_t cnt)
return -1;
/* Only do work on a 0 -> 1 transition of the refcount */
- if ((ret = git_atomic_inc(&init_count)) == 1) {
+ if ((ret = git_atomic32_inc(&init_count)) == 1) {
if (init_common(init_fns, cnt) < 0)
ret = -1;
}
@@ -136,7 +136,7 @@ int git_runtime_shutdown(void)
return -1;
/* Only do work on a 1 -> 0 transition of the refcount */
- if ((ret = git_atomic_dec(&init_count)) == 0)
+ if ((ret = git_atomic32_dec(&init_count)) == 0)
shutdown_common();
/* Exit the lock */
diff --git a/src/thread-utils.h b/src/thread-utils.h
index 10143475a..31a4c09e3 100644
--- a/src/thread-utils.h
+++ b/src/thread-utils.h
@@ -38,7 +38,7 @@ typedef struct {
#else
volatile int val;
#endif
-} git_atomic;
+} git_atomic32;
#ifdef GIT_ARCH_64
@@ -58,11 +58,11 @@ typedef git_atomic64 git_atomic_ssize;
#else
-typedef git_atomic git_atomic_ssize;
+typedef git_atomic32 git_atomic_ssize;
-#define git_atomic_ssize_set git_atomic_set
-#define git_atomic_ssize_add git_atomic_add
-#define git_atomic_ssize_get git_atomic_get
+#define git_atomic_ssize_set git_atomic32_set
+#define git_atomic_ssize_add git_atomic32_add
+#define git_atomic_ssize_get git_atomic32_get
#endif
@@ -74,7 +74,7 @@ typedef git_atomic git_atomic_ssize;
# include "unix/pthread.h"
#endif
-GIT_INLINE(void) git_atomic_set(git_atomic *a, int val)
+GIT_INLINE(void) git_atomic32_set(git_atomic32 *a, int val)
{
#if defined(GIT_WIN32)
InterlockedExchange(&a->val, (LONG)val);
@@ -87,7 +87,7 @@ GIT_INLINE(void) git_atomic_set(git_atomic *a, int val)
#endif
}
-GIT_INLINE(int) git_atomic_inc(git_atomic *a)
+GIT_INLINE(int) git_atomic32_inc(git_atomic32 *a)
{
#if defined(GIT_WIN32)
return InterlockedIncrement(&a->val);
@@ -100,7 +100,7 @@ GIT_INLINE(int) git_atomic_inc(git_atomic *a)
#endif
}
-GIT_INLINE(int) git_atomic_add(git_atomic *a, int32_t addend)
+GIT_INLINE(int) git_atomic32_add(git_atomic32 *a, int32_t addend)
{
#if defined(GIT_WIN32)
return InterlockedExchangeAdd(&a->val, addend);
@@ -113,7 +113,7 @@ GIT_INLINE(int) git_atomic_add(git_atomic *a, int32_t addend)
#endif
}
-GIT_INLINE(int) git_atomic_dec(git_atomic *a)
+GIT_INLINE(int) git_atomic32_dec(git_atomic32 *a)
{
#if defined(GIT_WIN32)
return InterlockedDecrement(&a->val);
@@ -126,7 +126,7 @@ GIT_INLINE(int) git_atomic_dec(git_atomic *a)
#endif
}
-GIT_INLINE(int) git_atomic_get(git_atomic *a)
+GIT_INLINE(int) git_atomic32_get(git_atomic32 *a)
{
#if defined(GIT_WIN32)
return (int)InterlockedCompareExchange(&a->val, 0, 0);
@@ -268,28 +268,28 @@ GIT_INLINE(int64_t) git_atomic64_get(git_atomic64 *a)
#define GIT_RWLOCK_STATIC_INIT 0
-GIT_INLINE(void) git_atomic_set(git_atomic *a, int val)
+GIT_INLINE(void) git_atomic32_set(git_atomic32 *a, int val)
{
a->val = val;
}
-GIT_INLINE(int) git_atomic_inc(git_atomic *a)
+GIT_INLINE(int) git_atomic32_inc(git_atomic32 *a)
{
return ++a->val;
}
-GIT_INLINE(int) git_atomic_add(git_atomic *a, int32_t addend)
+GIT_INLINE(int) git_atomic32_add(git_atomic32 *a, int32_t addend)
{
a->val += addend;
return a->val;
}
-GIT_INLINE(int) git_atomic_dec(git_atomic *a)
+GIT_INLINE(int) git_atomic32_dec(git_atomic32 *a)
{
return --a->val;
}
-GIT_INLINE(int) git_atomic_get(git_atomic *a)
+GIT_INLINE(int) git_atomic32_get(git_atomic32 *a)
{
return (int)a->val;
}
diff --git a/src/transports/local.c b/src/transports/local.c
index 4af85db81..bb31b1345 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -36,7 +36,7 @@ typedef struct {
char *url;
int direction;
int flags;
- git_atomic cancelled;
+ git_atomic32 cancelled;
git_repository *repo;
git_transport_message_cb progress_cb;
git_transport_message_cb error_cb;
@@ -671,7 +671,7 @@ static void local_cancel(git_transport *transport)
{
transport_local *t = (transport_local *)transport;
- git_atomic_set(&t->cancelled, 1);
+ git_atomic32_set(&t->cancelled, 1);
}
static int local_close(git_transport *transport)
diff --git a/src/transports/smart.c b/src/transports/smart.c
index 3b8a14a4c..da8fe8e22 100644
--- a/src/transports/smart.c
+++ b/src/transports/smart.c
@@ -30,7 +30,7 @@ static int git_smart__recv_cb(gitno_buffer *buf)
if (t->packetsize_cb && !t->cancelled.val) {
error = t->packetsize_cb(bytes_read, t->packetsize_payload);
if (error) {
- git_atomic_set(&t->cancelled, 1);
+ git_atomic32_set(&t->cancelled, 1);
return GIT_EUSER;
}
}
@@ -389,7 +389,7 @@ static void git_smart__cancel(git_transport *transport)
{
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
- git_atomic_set(&t->cancelled, 1);
+ git_atomic32_set(&t->cancelled, 1);
}
static int git_smart__is_connected(git_transport *transport)
diff --git a/src/transports/smart.h b/src/transports/smart.h
index 18e0b7e9f..a05d4c9e3 100644
--- a/src/transports/smart.h
+++ b/src/transports/smart.h
@@ -153,7 +153,7 @@ typedef struct {
git_vector refs;
git_vector heads;
git_vector common;
- git_atomic cancelled;
+ git_atomic32 cancelled;
packetsize_cb packetsize_cb;
void *packetsize_payload;
unsigned rpc : 1,
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index 18dcaa879..9482915d8 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -535,7 +535,7 @@ int git_smart__download_pack(
/* We might have something in the buffer already from negotiate_fetch */
if (t->buffer.offset > 0 && !t->cancelled.val)
if (t->packetsize_cb(t->buffer.offset, t->packetsize_payload))
- git_atomic_set(&t->cancelled, 1);
+ git_atomic32_set(&t->cancelled, 1);
}
if ((error = git_repository_odb__weakptr(&odb, repo)) < 0 ||
diff --git a/src/util.h b/src/util.h
index ef5e4eb12..6c7c4c284 100644
--- a/src/util.h
+++ b/src/util.h
@@ -169,19 +169,19 @@ extern int git__strncasecmp(const char *a, const char *b, size_t sz);
extern int git__strcasesort_cmp(const char *a, const char *b);
typedef struct {
- git_atomic refcount;
+ git_atomic32 refcount;
void *owner;
} git_refcount;
typedef void (*git_refcount_freeptr)(void *r);
#define GIT_REFCOUNT_INC(r) { \
- git_atomic_inc(&(r)->rc.refcount); \
+ git_atomic32_inc(&(r)->rc.refcount); \
}
#define GIT_REFCOUNT_DEC(_r, do_free) { \
git_refcount *r = &(_r)->rc; \
- int val = git_atomic_dec(&r->refcount); \
+ int val = git_atomic32_dec(&r->refcount); \
if (val <= 0 && r->owner == NULL) { do_free(_r); } \
}
@@ -191,7 +191,7 @@ typedef void (*git_refcount_freeptr)(void *r);
#define GIT_REFCOUNT_OWNER(r) git__load((r)->rc.owner)
-#define GIT_REFCOUNT_VAL(r) git_atomic_get((r)->rc.refcount)
+#define GIT_REFCOUNT_VAL(r) git_atomic32_get((r)->rc.refcount)
static signed char from_hex[] = {
diff --git a/tests/threads/diff.c b/tests/threads/diff.c
index 699642790..04c8cb97f 100644
--- a/tests/threads/diff.c
+++ b/tests/threads/diff.c
@@ -17,7 +17,7 @@
static git_repository *_repo;
static git_tree *_a, *_b;
-static git_atomic _counts[4];
+static git_atomic32 _counts[4];
static int _check_counts;
#ifdef GIT_WIN32
static int _retries;
@@ -66,10 +66,10 @@ static void free_trees(void)
git_tree_free(_b); _b = NULL;
if (_check_counts) {
- cl_assert_equal_i(288, git_atomic_get(&_counts[0]));
- cl_assert_equal_i(112, git_atomic_get(&_counts[1]));
- cl_assert_equal_i( 80, git_atomic_get(&_counts[2]));
- cl_assert_equal_i( 96, git_atomic_get(&_counts[3]));
+ cl_assert_equal_i(288, git_atomic32_get(&_counts[0]));
+ cl_assert_equal_i(112, git_atomic32_get(&_counts[1]));
+ cl_assert_equal_i( 80, git_atomic32_get(&_counts[2]));
+ cl_assert_equal_i( 96, git_atomic32_get(&_counts[3]));
}
}
@@ -107,14 +107,14 @@ static void *run_index_diffs(void *arg)
/* keep some diff stats to make sure results are as expected */
i = git_diff_num_deltas(diff);
- git_atomic_add(&_counts[0], (int32_t)i);
+ git_atomic32_add(&_counts[0], (int32_t)i);
exp[0] = (int)i;
while (i > 0) {
switch (git_diff_get_delta(diff, --i)->status) {
- case GIT_DELTA_MODIFIED: exp[1]++; git_atomic_inc(&_counts[1]); break;
- case GIT_DELTA_ADDED: exp[2]++; git_atomic_inc(&_counts[2]); break;
- case GIT_DELTA_DELETED: exp[3]++; git_atomic_inc(&_counts[3]); break;
+ case GIT_DELTA_MODIFIED: exp[1]++; git_atomic32_inc(&_counts[1]); break;
+ case GIT_DELTA_ADDED: exp[2]++; git_atomic32_inc(&_counts[2]); break;
+ case GIT_DELTA_DELETED: exp[3]++; git_atomic32_inc(&_counts[3]); break;
default: break;
}
}