summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-connection.c
diff options
context:
space:
mode:
authorJohn (J5) Palmieri <johnp@redhat.com>2006-08-16 22:30:15 +0000
committerJohn (J5) Palmieri <johnp@redhat.com>2006-08-16 22:30:15 +0000
commit14cc7d28a8308060428bbc9b3dd357eaea3a4749 (patch)
tree3b2a02f31eb74f3844ad8dcef0fca1d29151a9ed /dbus/dbus-connection.c
parent5b5da5297552919578266714fa7abf1e45d1131d (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-connection.c')
-rw-r--r--dbus/dbus-connection.c105
1 files changed, 55 insertions, 50 deletions
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index 2e942064..27720998 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -347,6 +347,33 @@ _dbus_connection_queue_received_message (DBusConnection *connection,
return TRUE;
}
+
+/**
+ * Gets the locks so we can examine them
+ *
+ * @param connection the connection.
+ * @param mutex_loc return for the location of the main mutex pointer
+ * @param dispatch_mutex_loc return location of the dispatch mutex pointer
+ * @param io_path_mutex_loc return location of the io_path mutex pointer
+ * @param dispatch_cond_loc return location of the dispatch conditional
+ * variable pointer
+ * @param io_path_cond_loc return location of the io_path conditional
+ * variable pointer
+ */
+void
+_dbus_connection_test_get_locks (DBusConnection *conn,
+ DBusMutex **mutex_loc,
+ DBusMutex **dispatch_mutex_loc,
+ DBusMutex **io_path_mutex_loc,
+ DBusCondVar **dispatch_cond_loc,
+ DBusCondVar **io_path_cond_loc)
+{
+ *mutex_loc = conn->mutex;
+ *dispatch_mutex_loc = conn->dispatch_mutex;
+ *io_path_mutex_loc = conn->io_path_mutex;
+ *dispatch_cond_loc = conn->dispatch_cond;
+ *io_path_cond_loc = conn->io_path_cond;
+}
#endif
/**
@@ -936,7 +963,8 @@ _dbus_connection_acquire_io_path (DBusConnection *connection,
while (connection->io_path_acquired)
{
_dbus_verbose ("%s waiting for IO path to be acquirable\n", _DBUS_FUNCTION_NAME);
- _dbus_condvar_wait (connection->io_path_cond, connection->io_path_mutex);
+ _dbus_condvar_wait (connection->io_path_cond,
+ connection->io_path_mutex);
}
}
}
@@ -1060,11 +1088,6 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
DBusWatchList *watch_list;
DBusTimeoutList *timeout_list;
DBusHashTable *pending_replies;
- DBusMutex *mutex;
- DBusMutex *io_path_mutex;
- DBusMutex *dispatch_mutex;
- DBusCondVar *dispatch_cond;
- DBusCondVar *io_path_cond;
DBusList *disconnect_link;
DBusMessage *disconnect_message;
DBusCounter *outgoing_counter;
@@ -1074,11 +1097,6 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
connection = NULL;
pending_replies = NULL;
timeout_list = NULL;
- mutex = NULL;
- io_path_mutex = NULL;
- dispatch_mutex = NULL;
- dispatch_cond = NULL;
- io_path_cond = NULL;
disconnect_link = NULL;
disconnect_message = NULL;
outgoing_counter = NULL;
@@ -1103,24 +1121,24 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
if (connection == NULL)
goto error;
- mutex = _dbus_mutex_new ();
- if (mutex == NULL)
+ _dbus_mutex_new_at_location (&connection->mutex);
+ if (connection->mutex == NULL)
goto error;
- io_path_mutex = _dbus_mutex_new ();
- if (io_path_mutex == NULL)
+ _dbus_mutex_new_at_location (&connection->io_path_mutex);
+ if (connection->io_path_mutex == NULL)
goto error;
- dispatch_mutex = _dbus_mutex_new ();
- if (dispatch_mutex == NULL)
+ _dbus_mutex_new_at_location (&connection->dispatch_mutex);
+ if (connection->dispatch_mutex == NULL)
goto error;
- dispatch_cond = _dbus_condvar_new ();
- if (dispatch_cond == NULL)
+ _dbus_condvar_new_at_location (&connection->dispatch_cond);
+ if (connection->dispatch_cond == NULL)
goto error;
- io_path_cond = _dbus_condvar_new ();
- if (io_path_cond == NULL)
+ _dbus_condvar_new_at_location (&connection->io_path_cond);
+ if (connection->io_path_cond == NULL)
goto error;
disconnect_message = dbus_message_new_signal (DBUS_PATH_LOCAL,
@@ -1146,11 +1164,6 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
_dbus_disable_sigpipe ();
connection->refcount.value = 1;
- connection->mutex = mutex;
- connection->dispatch_cond = dispatch_cond;
- connection->dispatch_mutex = dispatch_mutex;
- connection->io_path_cond = io_path_cond;
- connection->io_path_mutex = io_path_mutex;
connection->transport = transport;
connection->watches = watch_list;
connection->timeouts = timeout_list;
@@ -1189,24 +1202,15 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
if (disconnect_link != NULL)
_dbus_list_free_link (disconnect_link);
- if (io_path_cond != NULL)
- _dbus_condvar_free (io_path_cond);
-
- if (dispatch_cond != NULL)
- _dbus_condvar_free (dispatch_cond);
-
- if (mutex != NULL)
- _dbus_mutex_free (mutex);
-
- if (io_path_mutex != NULL)
- _dbus_mutex_free (io_path_mutex);
-
- if (dispatch_mutex != NULL)
- _dbus_mutex_free (dispatch_mutex);
-
if (connection != NULL)
- dbus_free (connection);
-
+ {
+ _dbus_condvar_free_at_location (&connection->io_path_cond);
+ _dbus_condvar_free_at_location (&connection->dispatch_cond);
+ _dbus_mutex_free_at_location (&connection->mutex);
+ _dbus_mutex_free_at_location (&connection->io_path_mutex);
+ _dbus_mutex_free_at_location (&connection->dispatch_mutex);
+ dbus_free (connection);
+ }
if (pending_replies)
_dbus_hash_table_unref (pending_replies);
@@ -1836,13 +1840,13 @@ _dbus_connection_last_unref (DBusConnection *connection)
_dbus_list_clear (&connection->link_cache);
- _dbus_condvar_free (connection->dispatch_cond);
- _dbus_condvar_free (connection->io_path_cond);
+ _dbus_condvar_free_at_location (&connection->dispatch_cond);
+ _dbus_condvar_free_at_location (&connection->io_path_cond);
- _dbus_mutex_free (connection->io_path_mutex);
- _dbus_mutex_free (connection->dispatch_mutex);
+ _dbus_mutex_free_at_location (&connection->io_path_mutex);
+ _dbus_mutex_free_at_location (&connection->dispatch_mutex);
- _dbus_mutex_free (connection->mutex);
+ _dbus_mutex_free_at_location (&connection->mutex);
dbus_free (connection);
}
@@ -3305,7 +3309,8 @@ _dbus_connection_acquire_dispatch (DBusConnection *connection)
while (connection->dispatch_acquired)
{
_dbus_verbose ("%s waiting for dispatch to be acquirable\n", _DBUS_FUNCTION_NAME);
- _dbus_condvar_wait (connection->dispatch_cond, connection->dispatch_mutex);
+ _dbus_condvar_wait (connection->dispatch_cond,
+ connection->dispatch_mutex);
}
_dbus_assert (!connection->dispatch_acquired);
@@ -4582,7 +4587,7 @@ dbus_bool_t
dbus_connection_allocate_data_slot (dbus_int32_t *slot_p)
{
return _dbus_data_slot_allocator_alloc (&slot_allocator,
- _DBUS_LOCK_NAME (connection_slots),
+ &_DBUS_LOCK_NAME (connection_slots),
slot_p);
}