};
#if HAVE_DECL_MSG_NOSIGNAL
-static dbus_bool_t _dbus_modify_sigpipe = FALSE;
+static DBusAtomic _dbus_modify_sigpipe = { FALSE };
#else
-static dbus_bool_t _dbus_modify_sigpipe = TRUE;
+static DBusAtomic _dbus_modify_sigpipe = { TRUE };
#endif
/**
if (objects == NULL)
goto error;
- if (_dbus_modify_sigpipe)
+ if (_dbus_atomic_get (&_dbus_modify_sigpipe) != 0)
_dbus_disable_sigpipe ();
/* initialized to 0: use atomic op to avoid mixing atomic and non-atomic */
*/
void
dbus_connection_set_change_sigpipe (dbus_bool_t will_modify_sigpipe)
-{
- _dbus_modify_sigpipe = will_modify_sigpipe != FALSE;
+{
+ if (will_modify_sigpipe)
+ _dbus_atomic_set_nonzero (&_dbus_modify_sigpipe);
+ else
+ _dbus_atomic_set_zero (&_dbus_modify_sigpipe);
}
/**
#endif
}
+/**
+ * Atomically set the value of an integer to 0.
+ *
+ * @param atomic pointer to the integer to set
+ */
+void
+_dbus_atomic_set_zero (DBusAtomic *atomic)
+{
+#if DBUS_USE_SYNC
+ /* Atomic version of "*atomic &= 0; return *atomic" */
+ __sync_and_and_fetch (&atomic->value, 0);
+#else
+ pthread_mutex_lock (&atomic_mutex);
+ atomic->value = 0;
+ pthread_mutex_unlock (&atomic_mutex);
+#endif
+}
+
+/**
+ * Atomically set the value of an integer to something nonzero.
+ *
+ * @param atomic pointer to the integer to set
+ */
+void
+_dbus_atomic_set_nonzero (DBusAtomic *atomic)
+{
+#if DBUS_USE_SYNC
+ /* Atomic version of "*atomic |= 1; return *atomic" */
+ __sync_or_and_fetch (&atomic->value, 1);
+#else
+ pthread_mutex_lock (&atomic_mutex);
+ atomic->value = 1;
+ pthread_mutex_unlock (&atomic_mutex);
+#endif
+}
+
/**
* Wrapper for poll().
*
return atomic->value;
}
+/**
+ * Atomically set the value of an integer to 0.
+ *
+ * @param atomic pointer to the integer to set
+ */
+void
+_dbus_atomic_set_zero (DBusAtomic *atomic)
+{
+ InterlockedExchange (&atomic->value, 0);
+}
+
+/**
+ * Atomically set the value of an integer to something nonzero.
+ *
+ * @param atomic pointer to the integer to set
+ */
+void
+_dbus_atomic_set_nonzero (DBusAtomic *atomic)
+{
+ InterlockedExchange (&atomic->value, 1);
+}
+
/**
* Called when the bus daemon is signaled to reload its configuration; any
* caches should be nuked. Of course any caches that need explicit reload
dbus_int32_t _dbus_atomic_dec (DBusAtomic *atomic);
DBUS_PRIVATE_EXPORT
dbus_int32_t _dbus_atomic_get (DBusAtomic *atomic);
+DBUS_PRIVATE_EXPORT
+void _dbus_atomic_set_zero (DBusAtomic *atomic);
+DBUS_PRIVATE_EXPORT
+void _dbus_atomic_set_nonzero (DBusAtomic *atomic);
#ifdef DBUS_WIN