* Creates a new pending reply object.
*
* @param connection connection where reply will arrive
- * @param timeout_milliseconds length of timeout, -1 for default, INT_MAX for no timeout
+ * @param timeout_milliseconds length of timeout, -1 (or
+ * #DBUS_TIMEOUT_USE_DEFAULT) for default,
+ * #DBUS_TIMEOUT_INFINITE for no timeout
* @param timeout_handler timeout handler, takes pending call as data
* @returns a new #DBusPendingCall or #NULL if no memory.
*/
return NULL;
}
- if (timeout_milliseconds != _DBUS_INT_MAX)
+ if (timeout_milliseconds != DBUS_TIMEOUT_INFINITE)
{
timeout = _dbus_timeout_new (timeout_milliseconds,
timeout_handler,
{
pending->timeout = NULL;
}
-
- pending->refcount.value = 1;
+
+ _dbus_atomic_inc (&pending->refcount);
pending->connection = connection;
_dbus_connection_ref_unlocked (pending->connection);
reply_link = _dbus_list_alloc_link (reply);
if (reply_link == NULL)
{
+ /* it's OK to unref this, nothing that could have attached a callback
+ * has ever seen it */
dbus_message_unref (reply);
return FALSE;
}
DBusPendingCall *
_dbus_pending_call_ref_unlocked (DBusPendingCall *pending)
{
- pending->refcount.value += 1;
-
+ _dbus_atomic_inc (&pending->refcount);
+
return pending;
}
void
_dbus_pending_call_unref_and_unlock (DBusPendingCall *pending)
{
- dbus_bool_t last_unref;
-
- _dbus_assert (pending->refcount.value > 0);
+ dbus_int32_t old_refcount;
- pending->refcount.value -= 1;
- last_unref = pending->refcount.value == 0;
+ old_refcount = _dbus_atomic_dec (&pending->refcount);
+ _dbus_assert (old_refcount > 0);
CONNECTION_UNLOCK (pending->connection);
- if (last_unref)
+
+ if (old_refcount == 1)
_dbus_pending_call_last_unref (pending);
}
*/
/**
+ * @def DBUS_TIMEOUT_INFINITE
+ *
+ * An integer constant representing an infinite timeout. This has the
+ * numeric value 0x7fffffff (the largest 32-bit signed integer).
+ *
+ * For source compatibility with D-Bus versions earlier than 1.4.12, use
+ * 0x7fffffff, or INT32_MAX (assuming your platform has it).
+ */
+
+/**
+ * @def DBUS_TIMEOUT_USE_DEFAULT
+ *
+ * An integer constant representing a request to use the default timeout.
+ * This has numeric value -1.
+ *
+ * For source compatibility with D-Bus versions earlier than 1.4.12, use a
+ * literal -1.
+ */
+
+/**
* @typedef DBusPendingCall
*
* Opaque data type representing a message pending.
{
_dbus_return_val_if_fail (pending != NULL, NULL);
- /* The connection lock is better than the global
- * lock in the atomic increment fallback
- */
-#ifdef DBUS_HAVE_ATOMIC_INT
_dbus_atomic_inc (&pending->refcount);
-#else
- CONNECTION_LOCK (pending->connection);
- _dbus_assert (pending->refcount.value > 0);
- pending->refcount.value += 1;
- CONNECTION_UNLOCK (pending->connection);
-#endif
-
return pending;
}
_dbus_return_if_fail (pending != NULL);
- /* More efficient to use the connection lock instead of atomic
- * int fallback if we lack atomic int decrement
- */
-#ifdef DBUS_HAVE_ATOMIC_INT
last_unref = (_dbus_atomic_dec (&pending->refcount) == 1);
-#else
- CONNECTION_LOCK (pending->connection);
- _dbus_assert (pending->refcount.value > 0);
- pending->refcount.value -= 1;
- last_unref = pending->refcount.value == 0;
- CONNECTION_UNLOCK (pending->connection);
-#endif
-
+
if (last_unref)
_dbus_pending_call_last_unref(pending);
}