dbus_bus_register: don't unref the messages with the lock held

Finalizing a message can call out to user code via dbus_message_set_data
(or to internal code not expecting locks to be held, via DBusCounter).

Reviewed-by: Colin Walters <walters@verbum.org>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34393
CRs-fixed: 330888
(cherry picked from commit 3b389b085b7b46ef13086fdb8e5bf2082bda037d)

Change-Id: I7b501d03de10ba78e2a2afab505264e14a4848ce
_dbus_connection_message_sent: rename to _unlocked

It's called with the connection's lock held.

Reviewed-by: Colin Walters <walters@verbum.org>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34393
CRs-fixed: 330888
(cherry picked from commit 79d6ea4597df388bcaa3aa36abf2aa953775f430)

Change-Id: I5263919346e6a4e426f8e0525794ac9850f00983
Add _dbus_counter_notify and call it after every adjustment

When fd-passing is implemented, adjustments happen in pairs; in that case
we coalesce the two calls into one.

Reviewed-by: Colin Walters <walters@verbum.org>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34393
CRs-fixed: 330888
(cherry picked from commit d4dcaf3649e6ff239e53514cebe2079e615877d3)

Change-Id: I54e8eb993b18fa5d2e7ca0d75e00a45f7a1dcf3a
Comment some places where it's OK to unref a message despite holding locks

In general, dbus_message_unref should be avoided while holding locks,
because it can invoke arbitrary user callbacks (via attached data, or
via DBusCounter).

Reviewed-by: Colin Walters <walters@verbum.org>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34393
CRs-fixed: 330888
(cherry picked from commit 91de1886a65c3f11585208da67a7cebf40ae4321)

Change-Id: Ie6c77c727a1b4ca0b3c7d1d8474ea4891f3fe31e
When attaching counters to messages, don't automatically notify callbacks

In all the places where counters are added, we're under a lock. The caller
knows what effect adding the counter might have, and can replicate it
in a lock-safe way if necessary.

Reviewed-by: Colin Walters <walters@verbum.org>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34393
CRs-fixed: 330888
(cherry picked from commit eca97e86621469d0168c49418c58c581bd27852e)

Change-Id: Ie0a072abef5b35f0dea059ef061d5d6f995999bb
Don't inline the contents of _dbus_connection_unlock

It's about to become more complex, to handle delayed deallocation of
messages in order to avoid triggering callbacks while locked.

Reviewed-by: Colin Walters <walters@verbum.org>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34393
CRs-fixed: 330888
(cherry picked from commit 0e9b67c50558f09377d867f49d207bccefbd14ad)

Change-Id: I4af9a83a4bc0a44d2591da92877517c3dc07dedf
Don't finalize sent or dispatched messages while under the connection lock

Finalizing a message can trigger callbacks; that's bad, if we have a
connection locked.

In particular, if a message is received by the "left side", passed to
the "right side" and sent (as in test/relay.c (see the diagram there)
or in dbus-daemon), then finalizing that message could result in the
live messages counter for the left side, and the outgoing messages counter
for the right side, both being decremented while under either side's
lock.

After a message is dispatched on the left side, finalizing it now drops
the lock temporarily, to avoid this problem.

After a message is sent on the right side, finalizing it is now deferred
until the right side unlocks, by moving it to a new queue of
"expired messages" which is automatically cleared every time we release
the lock.

The "live messages" counter for the "left" connection will now explicitly
take the left connection's lock before decrementing, to avoid
manipulating watches without a lock.

Reviewed-by: Colin Walters <walters@verbum.org>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34393
CRs-fixed: 330888
(cherry picked from commit 9a7ba540fcebdbff35e04d3cead02cdacae3b392)

Change-Id: Ib6976ada9c1da97c8811667c59a0f2e9178ea040
Merge "dbus_bus_register: don't unref the messages with the lock held"
Merge "_dbus_connection_message_sent: rename to _unlocked"
Merge "Add _dbus_counter_notify and call it after every adjustment"
Merge "Comment some places where it's OK to unref a message despite holding locks"
Merge "When attaching counters to messages, don't automatically notify callbacks"
Merge "Don't inline the contents of _dbus_connection_unlock"
Merge "Don't finalize sent or dispatched messages while under the connection lock"
Merge branch 'jb_2.5' of git://codeaurora.org/platform/external/dbus into cm-10.1

merge latest commits