mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-06-03 11:20:07 +02:00
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
This commit is contained in:
parent
920f54e795
commit
576e5f2f87
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user