diff options
author | John (J5) Palmieri <johnp@redhat.com> | 2006-08-16 22:30:15 +0000 |
---|---|---|
committer | John (J5) Palmieri <johnp@redhat.com> | 2006-08-16 22:30:15 +0000 |
commit | 14cc7d28a8308060428bbc9b3dd357eaea3a4749 (patch) | |
tree | 3b2a02f31eb74f3844ad8dcef0fca1d29151a9ed /dbus/dbus-dataslot.c | |
parent | 5b5da5297552919578266714fa7abf1e45d1131d (diff) |
* dbus/dbus-threads.c: Add static DBusList *uninitialized_mutex_list and
static DBusList *uninitialized_condvar_list to support new late
initialization threading model. In this model threads can be initialized
even after the D-Bus API has been used but still needs to be initialized
before the second thread has been started. Mutexes and condvar addresses
are stored in the two static lists and are replaced with actuall locks
when threads are initalized.
(_dbus_mutex_new_at_location): New method for creating a mutex and placing
the location into the static list
(_dbus_mutex_free_at_location): New method for removing a mutex location
from the static list and freeing the mutex
(_dbus_condvar_new_at_location): New method for creating a conditional
variable and placing the location into the static list
(_dbus_condvar_free_at_location): New method for removing a conditional
variable location from the static list and freeing the conditional variable
(init_uninitialized_locks): Atomic method which goes through the static
lists of mutex and condvar location and updates them with actuall locks
(init_global_locks): changed to init_locks
* dbus/dbus-connection.c:
(_dbus_connection_test_get_locks): New method for tests to check connections
(_dbus_connection_new_for_transport): Use the new at_location mutex and
condvar API
(dbus_connection_allocate_data_slot): Pass in the global lock address
to _dbus_data_slot_allocator_alloc
* dbus/dbus-dataslot.c:
(_dbus_data_slot_allocator_alloc): Use the address of the mutex
instead of the mutex itself
* dbus/dbus-message.c:
(dbus_message_allocate_data_slot): Pass in the global lock address
to _dbus_data_slot_allocator_alloc
* dbus/dbus-pending-call.c:
(dbus_pending_call_allocate_data_slot): Pass in the global lock address
to _dbus_data_slot_allocator_alloc
* dbus/dbus-server.c:
(_dbus_server_init_base): Use the new at_location mutex API
(dbus_server_allocate_data_slot): Pass in the global lock address
to _dbus_data_slot_allocator_alloc
* test/name-test/test-threads-init.c: New test case for late thread
initialization
Diffstat (limited to 'dbus/dbus-dataslot.c')
-rw-r--r-- | dbus/dbus-dataslot.c | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/dbus/dbus-dataslot.c b/dbus/dbus-dataslot.c index 78e94c37..d53f3bd7 100644 --- a/dbus/dbus-dataslot.c +++ b/dbus/dbus-dataslot.c @@ -46,7 +46,7 @@ _dbus_data_slot_allocator_init (DBusDataSlotAllocator *allocator) allocator->allocated_slots = NULL; allocator->n_allocated_slots = 0; allocator->n_used_slots = 0; - allocator->lock = NULL; + allocator->lock_loc = NULL; return TRUE; } @@ -59,26 +59,26 @@ _dbus_data_slot_allocator_init (DBusDataSlotAllocator *allocator) * is allocated and stored at *slot_id_p. * * @param allocator the allocator - * @param mutex the lock for this allocator + * @param mutex_loc the location lock for this allocator * @param slot_id_p address to fill with the slot ID * @returns #TRUE on success */ dbus_bool_t _dbus_data_slot_allocator_alloc (DBusDataSlotAllocator *allocator, - DBusMutex *mutex, + DBusMutex **mutex_loc, dbus_int32_t *slot_id_p) { dbus_int32_t slot; - if (!_dbus_mutex_lock (mutex)) + if (!_dbus_mutex_lock (*mutex_loc)) return FALSE; if (allocator->n_allocated_slots == 0) { - _dbus_assert (allocator->lock == NULL); - allocator->lock = mutex; + _dbus_assert (allocator->lock_loc == NULL); + allocator->lock_loc = mutex_loc; } - else if (allocator->lock != mutex) + else if (allocator->lock_loc != mutex_loc) { _dbus_warn ("D-Bus threads were initialized after first using the D-Bus library. If your application does not directly initialize threads or use D-Bus, keep in mind that some library or plugin may have used D-Bus or initialized threads behind your back. You can often fix this problem by calling dbus_init_threads() or dbus_g_threads_init() early in your main() method, before D-Bus is used."); _dbus_assert_not_reached ("exiting"); @@ -145,7 +145,7 @@ _dbus_data_slot_allocator_alloc (DBusDataSlotAllocator *allocator, slot, allocator, allocator->n_allocated_slots, allocator->n_used_slots); out: - _dbus_mutex_unlock (allocator->lock); + _dbus_mutex_unlock (*(allocator->lock_loc)); return slot >= 0; } @@ -164,7 +164,7 @@ void _dbus_data_slot_allocator_free (DBusDataSlotAllocator *allocator, dbus_int32_t *slot_id_p) { - _dbus_mutex_lock (allocator->lock); + _dbus_mutex_lock (*(allocator->lock_loc)); _dbus_assert (*slot_id_p < allocator->n_allocated_slots); _dbus_assert (allocator->allocated_slots[*slot_id_p].slot_id == *slot_id_p); @@ -174,7 +174,7 @@ _dbus_data_slot_allocator_free (DBusDataSlotAllocator *allocator, if (allocator->allocated_slots[*slot_id_p].refcount > 0) { - _dbus_mutex_unlock (allocator->lock); + _dbus_mutex_unlock (*(allocator->lock_loc)); return; } @@ -189,18 +189,18 @@ _dbus_data_slot_allocator_free (DBusDataSlotAllocator *allocator, if (allocator->n_used_slots == 0) { - DBusMutex *mutex = allocator->lock; + DBusMutex **mutex_loc = allocator->lock_loc; dbus_free (allocator->allocated_slots); allocator->allocated_slots = NULL; allocator->n_allocated_slots = 0; - allocator->lock = NULL; + allocator->lock_loc = NULL; - _dbus_mutex_unlock (mutex); + _dbus_mutex_unlock (*mutex_loc); } else { - _dbus_mutex_unlock (allocator->lock); + _dbus_mutex_unlock (*(allocator->lock_loc)); } } @@ -246,11 +246,11 @@ _dbus_data_slot_list_set (DBusDataSlotAllocator *allocator, * be e.g. realloc()ing allocated_slots. We avoid doing this if asserts * are disabled, since then the asserts are empty. */ - if (!_dbus_mutex_lock (allocator->lock)) + if (!_dbus_mutex_lock (*(allocator->lock_loc))) return FALSE; _dbus_assert (slot < allocator->n_allocated_slots); _dbus_assert (allocator->allocated_slots[slot].slot_id == slot); - _dbus_mutex_unlock (allocator->lock); + _dbus_mutex_unlock (*(allocator->lock_loc)); #endif if (slot >= list->n_slots) @@ -304,12 +304,12 @@ _dbus_data_slot_list_get (DBusDataSlotAllocator *allocator, * be e.g. realloc()ing allocated_slots. We avoid doing this if asserts * are disabled, since then the asserts are empty. */ - if (!_dbus_mutex_lock (allocator->lock)) + if (!_dbus_mutex_lock (*(allocator->lock_loc))) return NULL; _dbus_assert (slot >= 0); _dbus_assert (slot < allocator->n_allocated_slots); _dbus_assert (allocator->allocated_slots[slot].slot_id == slot); - _dbus_mutex_unlock (allocator->lock); + _dbus_mutex_unlock (*(allocator->lock_loc)); #endif if (slot >= list->n_slots) @@ -392,7 +392,7 @@ _dbus_data_slot_test (void) _dbus_data_slot_list_init (&list); - mutex = _dbus_mutex_new (); + _dbus_mutex_new_at_location (&mutex); if (mutex == NULL) _dbus_assert_not_reached ("failed to alloc mutex"); @@ -407,7 +407,7 @@ _dbus_data_slot_test (void) */ dbus_int32_t tmp = -1; - _dbus_data_slot_allocator_alloc (&allocator, mutex, &tmp); + _dbus_data_slot_allocator_alloc (&allocator, &mutex, &tmp); if (tmp != i) _dbus_assert_not_reached ("did not allocate slots in numeric order\n"); @@ -472,7 +472,7 @@ _dbus_data_slot_test (void) ++i; } - _dbus_mutex_free (mutex); + _dbus_mutex_free_at_location (&mutex); return TRUE; } |