device: Add a memory barrier when getting session pointer

The test suite ran into a very rare error where it seemed to get stuck
during authorization. A possible explanation is that the priv->_session
pointer re-fetching is optimized away and the pointer just continues to
contain the invalid placeholder rather than an updated value.

Use g_atomic_pointer_get in order to avoid this possibility entirely.
This commit is contained in:
Benjamin Berg
2021-07-24 14:20:55 +02:00
committed by Marco Trevisan
parent 2dd1cd8fc3
commit 161278cacd

View File

@ -168,7 +168,7 @@ session_data_get (FprintDevicePrivate *priv)
/* Get the current pointer and mark the pointer as "busy". */ /* Get the current pointer and mark the pointer as "busy". */
do do
{ {
cur = priv->_session; cur = g_atomic_pointer_get (&priv->_session);
/* Swap if cur is valid, otherwise busy loop. */ /* Swap if cur is valid, otherwise busy loop. */
} }
while (cur == invalid || !g_atomic_pointer_compare_and_exchange (&priv->_session, cur, invalid)); while (cur == invalid || !g_atomic_pointer_compare_and_exchange (&priv->_session, cur, invalid));
@ -205,7 +205,7 @@ session_data_set_new (FprintDevicePrivate *priv, gchar *sender, gchar *username)
/* Get the current (but not if it is busy) and put the new one in place. */ /* Get the current (but not if it is busy) and put the new one in place. */
do do
{ {
old = priv->_session; old = g_atomic_pointer_get (&priv->_session);
/* Swap if old is valid, otherwise busy loop as someone is ref'ing it currently. */ /* Swap if old is valid, otherwise busy loop as someone is ref'ing it currently. */
} }
while (old == invalid || !g_atomic_pointer_compare_and_exchange (&priv->_session, old, new)); while (old == invalid || !g_atomic_pointer_compare_and_exchange (&priv->_session, old, new));