summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2021-07-24 14:20:55 +0200
committerMarco Trevisan <mail@3v1n0.net>2021-07-26 13:09:13 +0000
commit161278cacd36706430b6b2e527436eb972122de9 (patch)
tree3f70a8d281f453156c6764fe9ce2b7ef7dd18f72
parent2dd1cd8fc3625b7295b1953fa5fe2c0871d917e9 (diff)
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.
-rw-r--r--src/device.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/device.c b/src/device.c
index 49cbdd5..155f659 100644
--- a/src/device.c
+++ b/src/device.c
@@ -168,7 +168,7 @@ session_data_get (FprintDevicePrivate *priv)
/* Get the current pointer and mark the pointer as "busy". */
do
{
- cur = priv->_session;
+ cur = g_atomic_pointer_get (&priv->_session);
/* Swap if cur is valid, otherwise busy loop. */
}
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. */
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. */
}
while (old == invalid || !g_atomic_pointer_compare_and_exchange (&priv->_session, old, new));