diff options
author | Rob Taylor <rob.taylor@collabora.co.uk> | 2007-01-08 08:41:11 +0000 |
---|---|---|
committer | Rob Taylor <rob.taylor@collabora.co.uk> | 2007-01-08 08:41:11 +0000 |
commit | c807d408924e9a9bcc7b2eb67b411c25888090ee (patch) | |
tree | 8c1414ec12b6e63a469865c6348784b8e8e81f75 | |
parent | 9bb928331e2ad602728320598698de90c9a246d6 (diff) | |
download | dbus-glib-c807d408924e9a9bcc7b2eb67b411c25888090ee.tar.gz |
Use dbus_threads_init_default() rather than using own threading primitives.
Modifies dbus_g_threads_init() to just call dbus_threads_init_default(), which with current dbus gives us full thread primitives with recursive locking.
Fixes #9259.
-rw-r--r-- | dbus/dbus-gthread.c | 143 |
1 files changed, 7 insertions, 136 deletions
diff --git a/dbus/dbus-gthread.c b/dbus/dbus-gthread.c index 1b925cd..3fc465e 100644 --- a/dbus/dbus-gthread.c +++ b/dbus/dbus-gthread.c @@ -25,145 +25,16 @@ #include <glib.h> #include <dbus/dbus.h> -#include <dbus/dbus-glib.h> -#include <dbus/dbus-glib-lowlevel.h> - -/** @addtogroup DBusGLibInternals - * @{ - */ - -static DBusMutex * dbus_gmutex_new (void); -static void dbus_gmutex_free (DBusMutex *mutex); -static dbus_bool_t dbus_gmutex_lock (DBusMutex *mutex); -static dbus_bool_t dbus_gmutex_unlock (DBusMutex *mutex); - - -static DBusCondVar* dbus_gcondvar_new (void); -static void dbus_gcondvar_free (DBusCondVar *cond); -static void dbus_gcondvar_wait (DBusCondVar *cond, - DBusMutex *mutex); -static dbus_bool_t dbus_gcondvar_wait_timeout (DBusCondVar *cond, - DBusMutex *mutex, - int timeout_msec); -static void dbus_gcondvar_wake_one (DBusCondVar *cond); -static void dbus_gcondvar_wake_all (DBusCondVar *cond); - - -static const DBusThreadFunctions functions = -{ - DBUS_THREAD_FUNCTIONS_MUTEX_NEW_MASK | - DBUS_THREAD_FUNCTIONS_MUTEX_FREE_MASK | - DBUS_THREAD_FUNCTIONS_MUTEX_LOCK_MASK | - DBUS_THREAD_FUNCTIONS_MUTEX_UNLOCK_MASK | - DBUS_THREAD_FUNCTIONS_CONDVAR_NEW_MASK | - DBUS_THREAD_FUNCTIONS_CONDVAR_FREE_MASK | - DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_MASK | - DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_TIMEOUT_MASK | - DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ONE_MASK| - DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ALL_MASK, - dbus_gmutex_new, - dbus_gmutex_free, - dbus_gmutex_lock, - dbus_gmutex_unlock, - dbus_gcondvar_new, - dbus_gcondvar_free, - dbus_gcondvar_wait, - dbus_gcondvar_wait_timeout, - dbus_gcondvar_wake_one, - dbus_gcondvar_wake_all -}; - -static DBusMutex * -dbus_gmutex_new (void) -{ - GMutex *mutex; - - mutex = g_mutex_new (); - - return (DBusMutex *)mutex; -} - -static void -dbus_gmutex_free (DBusMutex *mutex) -{ - g_mutex_free ((GMutex *)mutex); -} - -static dbus_bool_t -dbus_gmutex_lock (DBusMutex *mutex) -{ - g_mutex_lock ((GMutex *)mutex); - - return TRUE; -} - -static dbus_bool_t -dbus_gmutex_unlock (DBusMutex *mutex) -{ - g_mutex_unlock ((GMutex *)mutex); - - return TRUE; -} - -static DBusCondVar* -dbus_gcondvar_new (void) -{ - return (DBusCondVar*)g_cond_new (); -} - -static void -dbus_gcondvar_free (DBusCondVar *cond) -{ - g_cond_free ((GCond *)cond); -} - -static void -dbus_gcondvar_wait (DBusCondVar *cond, - DBusMutex *mutex) -{ - g_cond_wait ((GCond *)cond, (GMutex *)mutex); -} - -static dbus_bool_t -dbus_gcondvar_wait_timeout (DBusCondVar *cond, - DBusMutex *mutex, - int timeout_msec) -{ - GTimeVal now; - - g_get_current_time (&now); - - now.tv_sec += timeout_msec / 1000; - now.tv_usec += (timeout_msec % 1000) * 1000; - if (now.tv_usec > G_USEC_PER_SEC) - { - now.tv_sec += 1; - now.tv_usec -= G_USEC_PER_SEC; - } - - return g_cond_timed_wait ((GCond *)cond, (GMutex *)mutex, &now); -} - -static void -dbus_gcondvar_wake_one (DBusCondVar *cond) -{ - g_cond_signal ((GCond *)cond); -} - -static void -dbus_gcondvar_wake_all (DBusCondVar *cond) -{ - g_cond_broadcast ((GCond *)cond); -} - -/** @} End of internals */ /** @addtogroup DBusGLib * @{ */ + /** - * Initializes the D-BUS thread system to use - * GLib threads. This function may only be called + * dbus_g_thread_init: + * + * Initializes the D-BUS thread system. + * This function may only be called * once and must be called prior to calling any * other function in the D-BUS API. */ @@ -172,8 +43,8 @@ dbus_g_thread_init (void) { if (!g_thread_supported ()) g_error ("g_thread_init() must be called before dbus_threads_init()"); - - dbus_threads_init (&functions); + + dbus_threads_init_default (); } /** @} end of public API */ |