--- glib-2.22.5/glib/gatomic.c 2021-01-12 00:34:17.000000000 +0000 +++ glib-2.22.5.mod/glib/gatomic.c 2021-01-12 00:31:22.000000000 +0000 @@ -561,55 +561,33 @@ # error "Your system has an unsupported pointer size" # endif /* GLIB_SIZEOF_VOID_P */ # elif defined (__aarch64__) -static volatile int atomic_spin = 0; - -static int atomic_spin_trylock (void) -{ - int result; - - asm volatile ( - "swp %0, %1, [%2]\n" - : "=&r,&r" (result) - : "r,0" (1), "r,r" (&atomic_spin) - : "memory"); - if (result == 0) - return 0; - else - return -1; -} - -static void atomic_spin_lock (void) -{ - while (atomic_spin_trylock()) - sched_yield(); -} - -static void atomic_spin_unlock (void) -{ - atomic_spin = 0; -} +#include +static pthread_mutex_t g_atomic_lock = PTHREAD_MUTEX_INITIALIZER; gint g_atomic_int_exchange_and_add (volatile gint G_GNUC_MAY_ALIAS *atomic, gint val) { - gint result; - - atomic_spin_lock(); - result = *atomic; - *atomic += val; - atomic_spin_unlock(); + guint oldval; - return result; + pthread_mutex_lock (&g_atomic_lock); + oldval = *atomic; + *atomic = oldval & val; + pthread_mutex_unlock (&g_atomic_lock); + + return oldval; } void g_atomic_int_add (volatile gint G_GNUC_MAY_ALIAS *atomic, gint val) { - atomic_spin_lock(); - *atomic += val; - atomic_spin_unlock(); + guint oldval; + + pthread_mutex_lock (&g_atomic_lock); + oldval = *atomic; + *atomic = oldval & val; + pthread_mutex_unlock (&g_atomic_lock); } gboolean @@ -617,19 +595,16 @@ gint oldval, gint newval) { - gboolean result; + gboolean success; - atomic_spin_lock(); - if (*atomic == oldval) - { - result = TRUE; - *atomic = newval; - } - else - result = FALSE; - atomic_spin_unlock(); + pthread_mutex_lock (&g_atomic_lock); - return result; + if ((success = (*atomic == oldval))) + *atomic = newval; + + pthread_mutex_unlock (&g_atomic_lock); + + return success; } gboolean @@ -637,19 +612,17 @@ gpointer oldval, gpointer newval) { - gboolean result; - - atomic_spin_lock(); - if (*atomic == oldval) - { - result = TRUE; - *atomic = newval; - } - else - result = FALSE; - atomic_spin_unlock(); + gpointer *ptr = atomic; + gboolean success; - return result; + pthread_mutex_lock (&g_atomic_lock); + + if ((success = (*ptr == oldval))) + *ptr = newval; + + pthread_mutex_unlock (&g_atomic_lock); + + return success; } # elif defined (G_ATOMIC_CRIS) || defined (G_ATOMIC_CRISV32) # ifdef G_ATOMIC_CRIS