summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2011-07-14 17:07:08 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2011-07-25 18:15:34 +0100
commitb997bf4ee29a96744ebcf6ecffa9f6fcb86654e0 (patch)
tree3634e1a96fd5bbdf326b1ac32ca9fee272c56ebc
parentc62b886119b1b5609ef5de2eab30776524974e65 (diff)
Add _dbus_atomic_get implemented in terms of inc, dec
Reviewed-by: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=38005
-rw-r--r--dbus/dbus-sysdeps.c24
-rw-r--r--dbus/dbus-sysdeps.h1
2 files changed, 25 insertions, 0 deletions
diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c
index bab516de..18f69dc3 100644
--- a/dbus/dbus-sysdeps.c
+++ b/dbus/dbus-sysdeps.c
@@ -1067,6 +1067,30 @@ _dbus_strerror_from_errno (void)
return _dbus_strerror (errno);
}
+/**
+ * Atomically get the value of an integer. It may change at any time
+ * thereafter, so this is mostly only useful for assertions.
+ *
+ * This function temporarily increases the atomic integer, so only
+ * use it in contexts where that would be OK (such as refcounts).
+ *
+ * @param atomic pointer to the integer to increment
+ * @returns the value at this moment
+ */
+dbus_int32_t
+_dbus_atomic_get (DBusAtomic *atomic)
+{
+ dbus_int32_t old_value;
+
+ /* On Windows we use InterlockedIncrement and InterlockedDecrement,
+ * and there is no InterlockedGet, so we have to change the value.
+ * Increasing it is less likely to have bad side-effects (for instance,
+ * it's OK for refcounts). */
+ old_value = _dbus_atomic_inc (atomic);
+ _dbus_atomic_dec (atomic);
+ return old_value;
+}
+
/** @} end of sysdeps */
/* tests in dbus-sysdeps-util.c */
diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h
index 22d7969e..54a4cd7e 100644
--- a/dbus/dbus-sysdeps.h
+++ b/dbus/dbus-sysdeps.h
@@ -244,6 +244,7 @@ struct DBusAtomic
dbus_int32_t _dbus_atomic_inc (DBusAtomic *atomic);
dbus_int32_t _dbus_atomic_dec (DBusAtomic *atomic);
+dbus_int32_t _dbus_atomic_get (DBusAtomic *atomic);
/* AIX uses different values for poll */