[glib: 3/3] Merge branch 'atomic-exchange-pre-value' into 'main'
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 3/3] Merge branch 'atomic-exchange-pre-value' into 'main'
- Date: Thu, 23 Jun 2022 13:19:09 +0000 (UTC)
commit e5ccbe09da3c16608d39fac033ce3928caad3269
Merge: 5655af6ada 922bc1d995
Author: Philip Withnall <philip tecnocode co uk>
Date: Thu Jun 23 13:19:05 2022 +0000
Merge branch 'atomic-exchange-pre-value' into 'main'
gatomic: Add Compare and Exchange functions that returns the previous value
See merge request GNOME/glib!2766
docs/reference/glib/glib-sections.txt | 2 +
glib/gatomic.c | 132 ++++++++++++++++++++++++++++++++++
glib/gatomic.h | 62 ++++++++++++++--
glib/tests/atomic.c | 97 ++++++++++++++++++++++++-
glib/tests/cxx.cpp | 40 +++++++++++
meson.build | 2 +-
6 files changed, 328 insertions(+), 7 deletions(-)
---
diff --cc glib/gatomic.c
index 1ab4fde91c,499fd336f3..6c1ea768e7
--- a/glib/gatomic.c
+++ b/glib/gatomic.c
@@@ -430,9 -463,44 +463,44 @@@ gboolea
oldval, newval);
}
+ /**
+ * g_atomic_pointer_compare_and_exchange_full:
+ * @atomic: (not nullable): a pointer to a #gpointer-sized value
+ * @oldval: the value to compare with
+ * @newval: the value to conditionally replace with
+ * @preval: (not nullable) (out): the contents of @atomic before this operation
+ *
+ * Compares @atomic to @oldval and, if equal, sets it to @newval.
+ * If @atomic was not equal to @oldval then no change occurs.
+ * In any case the value of @atomic before this operation is stored in @preval.
+ *
+ * This compare and exchange is done atomically.
+ *
+ * Think of this operation as an atomic version of
+ * `{ *preval = *atomic; if (*atomic == oldval) { *atomic = newval; return TRUE; } else return FALSE; }`.
+ *
+ * This call acts as a full compiler and hardware memory barrier.
+ *
+ * See also g_atomic_pointer_compare_and_exchange()
+ *
+ * Returns: %TRUE if the exchange took place
+ *
+ * Since: 2.74
+ **/
+ gboolean
+ (g_atomic_pointer_compare_and_exchange_full) (void *atomic,
+ gpointer oldval,
+ gpointer newval,
+ void *preval)
+ {
+ return g_atomic_pointer_compare_and_exchange_full ((gpointer *) atomic,
+ oldval, newval,
+ (gpointer *) preval);
+ }
+
/**
* g_atomic_pointer_exchange:
- * @atomic: a pointer to a #gint or #guint
+ * @atomic: a pointer to a #gpointer-sized value
* @newval: the value to replace with
*
* Sets the @atomic to @newval and returns the old value from @atomic.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]