summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-sysdeps-unix.c
diff options
context:
space:
mode:
Diffstat (limited to 'dbus/dbus-sysdeps-unix.c')
-rw-r--r--dbus/dbus-sysdeps-unix.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
index f4afad89..9b6457b2 100644
--- a/dbus/dbus-sysdeps-unix.c
+++ b/dbus/dbus-sysdeps-unix.c
@@ -1428,6 +1428,53 @@ _dbus_getuid (void)
return getuid ();
}
+/**
+ * Atomically increments an integer
+ *
+ * @param atomic pointer to the integer to increment
+ * @returns the value before incrementing
+ *
+ * @todo implement arch-specific faster atomic ops
+ */
+dbus_int32_t
+_dbus_atomic_inc (DBusAtomic *atomic)
+{
+#ifdef DBUS_USE_ATOMIC_INT_486
+ return atomic_exchange_and_add (atomic, 1);
+#else
+ dbus_int32_t res;
+ _DBUS_LOCK (atomic);
+ res = atomic->value;
+ atomic->value += 1;
+ _DBUS_UNLOCK (atomic);
+ return res;
+#endif
+}
+
+/**
+ * Atomically decrement an integer
+ *
+ * @param atomic pointer to the integer to decrement
+ * @returns the value before decrementing
+ *
+ * @todo implement arch-specific faster atomic ops
+ */
+dbus_int32_t
+_dbus_atomic_dec (DBusAtomic *atomic)
+{
+#ifdef DBUS_USE_ATOMIC_INT_486
+ return atomic_exchange_and_add (atomic, -1);
+#else
+ dbus_int32_t res;
+
+ _DBUS_LOCK (atomic);
+ res = atomic->value;
+ atomic->value -= 1;
+ _DBUS_UNLOCK (atomic);
+ return res;
+#endif
+}
+
#ifdef DBUS_BUILD_TESTS
/** Gets our GID
* @returns process GID