mirror of
https://github.com/ostreedev/ostree.git
synced 2025-01-27 18:04:17 +03:00
[TSAN] Rework assertions to always access refcount atomically
`-fsanitize=address` complained that the `refcount > 0` assertions were reading without atomics. We can fix this by reworking them to read the previous value. Closes: #582 Approved by: jlebon
This commit is contained in:
parent
f0519e541f
commit
c1c70bceb7
@ -128,11 +128,10 @@ G_DEFINE_TYPE (OstreeFetcher, _ostree_fetcher, G_TYPE_OBJECT)
|
||||
static ThreadClosure *
|
||||
thread_closure_ref (ThreadClosure *thread_closure)
|
||||
{
|
||||
int refcount;
|
||||
g_return_val_if_fail (thread_closure != NULL, NULL);
|
||||
g_return_val_if_fail (thread_closure->ref_count > 0, NULL);
|
||||
|
||||
g_atomic_int_inc (&thread_closure->ref_count);
|
||||
|
||||
refcount = g_atomic_int_add (&thread_closure->ref_count, 1);
|
||||
g_assert (refcount > 0);
|
||||
return thread_closure;
|
||||
}
|
||||
|
||||
@ -140,7 +139,6 @@ static void
|
||||
thread_closure_unref (ThreadClosure *thread_closure)
|
||||
{
|
||||
g_return_if_fail (thread_closure != NULL);
|
||||
g_return_if_fail (thread_closure->ref_count > 0);
|
||||
|
||||
if (g_atomic_int_dec_and_test (&thread_closure->ref_count))
|
||||
{
|
||||
@ -197,11 +195,10 @@ pending_task_compare (gconstpointer a,
|
||||
static OstreeFetcherPendingURI *
|
||||
pending_uri_ref (OstreeFetcherPendingURI *pending)
|
||||
{
|
||||
gint refcount;
|
||||
g_return_val_if_fail (pending != NULL, NULL);
|
||||
g_return_val_if_fail (pending->ref_count > 0, NULL);
|
||||
|
||||
g_atomic_int_inc (&pending->ref_count);
|
||||
|
||||
refcount = g_atomic_int_add (&pending->ref_count, 1);
|
||||
g_assert (refcount > 0);
|
||||
return pending;
|
||||
}
|
||||
|
||||
|
@ -2959,7 +2959,8 @@ ostree_repo_commit_modifier_new (OstreeRepoCommitModifierFlags flags,
|
||||
OstreeRepoCommitModifier *
|
||||
ostree_repo_commit_modifier_ref (OstreeRepoCommitModifier *modifier)
|
||||
{
|
||||
g_atomic_int_inc (&modifier->refcount);
|
||||
gint refcount = g_atomic_int_add (&modifier->refcount, 1);
|
||||
g_assert (refcount > 0);
|
||||
return modifier;
|
||||
}
|
||||
|
||||
|
@ -161,11 +161,10 @@ ost_remote_new_from_keyfile (GKeyFile *keyfile,
|
||||
static OstreeRemote *
|
||||
ost_remote_ref (OstreeRemote *remote)
|
||||
{
|
||||
gint refcount;
|
||||
g_return_val_if_fail (remote != NULL, NULL);
|
||||
g_return_val_if_fail (remote->ref_count > 0, NULL);
|
||||
|
||||
g_atomic_int_inc (&remote->ref_count);
|
||||
|
||||
refcount = g_atomic_int_add (&remote->ref_count, 1);
|
||||
g_assert (refcount > 0);
|
||||
return remote;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user