diff options
author | Havoc Pennington <hp@redhat.com> | 2003-05-12 02:44:45 +0000 |
---|---|---|
committer | Havoc Pennington <hp@redhat.com> | 2003-05-12 02:44:45 +0000 |
commit | d4e80132af03363a2f861cfd611847ee8758aed9 (patch) | |
tree | 96b06426382cb0df1db9dd06cf6d0c5b837d7e30 /dbus/dbus-message.c | |
parent | ab10ae902d8aa7c2b98fd080a7458127b1b8e648 (diff) |
2003-05-11 Havoc Pennington <hp@pobox.com>
* dbus/dbus-marshal.c (_dbus_marshal_validate_arg): fix to avoid
calling _dbus_marshal_validate_arg() for every byte in a byte
array, etc.
* dbus/dbus-message-handler.c: use atomic reference counting to
reduce number of locks slightly; the global lock in here sucks
* dbus/dbus-connection.c
(_dbus_connection_update_dispatch_status_and_unlock): variant of
update_dispatch_status that can be called with lock held; then use
in a couple places to reduce locking/unlocking
(dbus_connection_send): hold the lock over the whole function
instead of acquiring it twice.
* dbus/dbus-timeout.c (_dbus_timeout_new): handle OOM
* bus/connection.c (bus_connections_setup_connection): fix access
to already-freed memory.
* dbus/dbus-connection.c: keep a little cache of linked list
nodes, to avoid using the global linked list alloc lock in the
normal send-message case. Instead we just use the connection lock
that we already have to take.
* dbus/dbus-list.c (_dbus_list_find_last): new function
* dbus/dbus-sysdeps.c (_dbus_atomic_inc, _dbus_atomic_dec):
change to use a struct for the atomic type; fix docs,
they return value before increment, not after increment.
* dbus/dbus-string.c (_dbus_string_append_4_aligned)
(_dbus_string_append_8_aligned): new functions to try to
microoptimize this operation.
(reallocate_for_length): break this out of set_length(), to
improve profile info, and also so we can consider inlining the
set_length() part.
* dbus/dbus-message.c (dbus_message_new_empty_header): init data
strings with some preallocation, cuts down on our calls to realloc
a fair bit. Though if we can get the "move entire string to empty
string" optimization below to kick in here, it would be better.
* dbus/dbus-string.c (_dbus_string_move): just call
_dbus_string_move_len
(_dbus_string_move_len): add a special case for moving
an entire string into an empty string; we can just
swap the string data instead of doing any reallocs.
(_dbus_string_init_preallocated): new function
Diffstat (limited to 'dbus/dbus-message.c')
-rw-r--r-- | dbus/dbus-message.c | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index 29209106..7c89d734 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -81,7 +81,7 @@ typedef struct */ struct DBusMessage { - volatile dbus_atomic_t refcount; /**< Reference count */ + DBusAtomic refcount; /**< Reference count */ DBusString header; /**< Header network data, stored * separately from body so we can @@ -772,15 +772,26 @@ _dbus_message_add_size_counter (DBusMessage *message, * the counter by the size of this message. * * @param message the message + * @param link_return return the link used * @param counter the counter */ void _dbus_message_remove_size_counter (DBusMessage *message, - DBusCounter *counter) + DBusCounter *counter, + DBusList **link_return) { - if (!_dbus_list_remove_last (&message->size_counters, - counter)) - _dbus_assert_not_reached ("Removed a message size counter that was not added"); + DBusList *link; + + link = _dbus_list_find_last (&message->size_counters, + counter); + _dbus_assert (link != NULL); + + _dbus_list_unlink (&message->size_counters, + link); + if (link_return) + *link_return = link; + else + _dbus_list_free_link (link); _dbus_counter_adjust (counter, message->size_counter_delta); @@ -898,7 +909,7 @@ dbus_message_new_empty_header (void) if (message == NULL) return NULL; - message->refcount = 1; + message->refcount.value = 1; message->byte_order = DBUS_COMPILER_BYTE_ORDER; message->client_serial = 0; message->reply_serial = 0; @@ -910,13 +921,13 @@ dbus_message_new_empty_header (void) ++i; } - if (!_dbus_string_init (&message->header)) + if (!_dbus_string_init_preallocated (&message->header, 64)) { dbus_free (message); return NULL; } - if (!_dbus_string_init (&message->body)) + if (!_dbus_string_init_preallocated (&message->body, 64)) { _dbus_string_free (&message->header); dbus_free (message); @@ -1076,7 +1087,7 @@ dbus_message_copy (const DBusMessage *message) if (retval == NULL) return NULL; - retval->refcount = 1; + retval->refcount.value = 1; retval->byte_order = message->byte_order; retval->client_serial = message->client_serial; retval->reply_serial = message->reply_serial; @@ -1134,12 +1145,12 @@ dbus_message_copy (const DBusMessage *message) void dbus_message_ref (DBusMessage *message) { - volatile dbus_atomic_t refcount; + dbus_int32_t old_refcount; _dbus_return_if_fail (message != NULL); - refcount = _dbus_atomic_inc (&message->refcount); - _dbus_assert (refcount > 1); + old_refcount = _dbus_atomic_inc (&message->refcount); + _dbus_assert (old_refcount >= 1); } static void @@ -1163,15 +1174,15 @@ free_size_counter (void *element, void dbus_message_unref (DBusMessage *message) { - volatile dbus_atomic_t refcount; + dbus_int32_t old_refcount; _dbus_return_if_fail (message != NULL); - refcount = _dbus_atomic_dec (&message->refcount); + old_refcount = _dbus_atomic_dec (&message->refcount); - _dbus_assert (refcount >= 0); + _dbus_assert (old_refcount >= 0); - if (refcount == 0) + if (old_refcount == 1) { _dbus_list_foreach (&message->size_counters, free_size_counter, message); |