summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2022-06-20 18:57:36 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2022-06-23 20:01:12 +0200
commit576e5f2f875125c4ee06505790da22a2878c9198 (patch)
tree70f23def1b262b8a4a27cbbc55c927ad9d720acf
parent920f54e795b1577a3270c6322f547e0963b2d32a (diff)
downloadglib-576e5f2f875125c4ee06505790da22a2878c9198.tar.gz
cancellable: Use more atomic exchanges operations
We used to do get and set atomic operations pair, but these may be unsafe in some cases as threads may rely on data that is changed in in between them, however this is not a problem if we do exchange the pointers. So just use exchange ops, in this way we can avoid lock/unlock mutex dances
-rw-r--r--gio/gcancellable.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/gio/gcancellable.c b/gio/gcancellable.c
index 64755206b..13a891a69 100644
--- a/gio/gcancellable.c
+++ b/gio/gcancellable.c
@@ -273,12 +273,10 @@ g_cancellable_reset (GCancellable *cancellable)
g_cond_wait (&cancellable_cond, &cancellable_mutex);
}
- if (g_atomic_int_get (&priv->cancelled))
+ if (g_atomic_int_exchange (&priv->cancelled, FALSE))
{
if (priv->wakeup)
GLIB_PRIVATE_CALL (g_wakeup_acknowledge) (priv->wakeup);
-
- g_atomic_int_set (&priv->cancelled, FALSE);
}
g_mutex_unlock (&cancellable_mutex);
@@ -497,13 +495,12 @@ g_cancellable_cancel (GCancellable *cancellable)
g_mutex_lock (&cancellable_mutex);
- if (g_atomic_int_get (&priv->cancelled))
+ if (g_atomic_int_exchange (&priv->cancelled, TRUE))
{
g_mutex_unlock (&cancellable_mutex);
return;
}
- g_atomic_int_set (&priv->cancelled, TRUE);
priv->cancelled_running = TRUE;
if (priv->wakeup)