From fe4018941190f8bf020e4a8ed2999c212e0e113d Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Sat, 15 Feb 2003 16:25:08 +0000 Subject: 2003-02-15 Alexander Larsson * dbus/dbus-threads.c: * dbus/dbus-threads.h: Add condvars. Remove static mutext from API. Implement static mutexes by initializing them from threads_init. * glib/dbus-gthread.c: * qt/dbus-qthread.cpp: Update with the thread api changes. * dbus/dbus-list.c: * dbus/dbus-list.h: Turn StaticMutex into normal mutex + init function. Export new functions _dbus_list_alloc_link, _dbus_list_free_link, _dbus_list_append_link, _dbus_list_prepend_link * dbus/dbus-sysdeps.c: * dbus/dbus-sysdeps.h: New type dbus_atomic_t, and new functions _dbus_atomic_inc, _dbus_atomic_dec. Only slow fallback implementation at the moment. * dbus/dbus-protocol.h: Add DBUS_MESSAGE_LOCAL_DISCONNECT define * dbus/dbus-message.c: Make ref/unref atomic. Fix some docs. * dbus/dbus-connection-internal.h: * dbus/dbus-connection.c: * dbus/dbus-connection.h: Make threadsafe. Change _peek to _borrow,_return & _steal_borrowed. Change disconnect callback to event. Make dbus_connection_dispatch_messages reentrant. * dbus/dbus-transport.c: Don't ref the connection on calls to the transport implementation. * dbus/dbus-message-handler.c: Make threadsafe. * glib/dbus-gmain.c: Don't use peek_message anymore * test/Makefile.am: * test/debug-thread.c: * test/debug-thread.h: Simple thread implementation that asserts() on deadlocks in single-threaded code. * test/bus-test.c: (main) Call debug_threads_init. * test/watch.c: Use disconnect message instead of disconnect callback. * bus/connection.c: * bus/connection.h: Don't call dbus_connection_set_disconnect_function. Instead export bus_connection_disconnect. * bus/dispatch.c: Call bus_connection_disconnect when we get a disconnected message. --- test/debug-thread.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 test/debug-thread.c (limited to 'test/debug-thread.c') diff --git a/test/debug-thread.c b/test/debug-thread.c new file mode 100644 index 00000000..5ef3ba44 --- /dev/null +++ b/test/debug-thread.c @@ -0,0 +1,161 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-test.c Program to run all tests + * + * Copyright (C) 2002 Red Hat Inc. + * + * Licensed under the Academic Free License version 1.2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include "debug-thread.h" + +#define DBUS_COMPILATION +#include +#undef DBUS_COMPILATION + + +static DBusMutex * tmutex_new (void); +static void tmutex_free (DBusMutex *mutex); +static dbus_bool_t tmutex_lock (DBusMutex *mutex); +static dbus_bool_t tmutex_unlock (DBusMutex *mutex); + +static DBusCondVar*tcondvar_new (void); +static void tcondvar_free (DBusCondVar *cond); +static void tcondvar_wait (DBusCondVar *cond, + DBusMutex *mutex); +static dbus_bool_t tcondvar_wait_timeout (DBusCondVar *cond, + DBusMutex *mutex, + int timeout_msec); +static void tcondvar_wake_one (DBusCondVar *cond); +static void tcondvar_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, + tmutex_new, + tmutex_free, + tmutex_lock, + tmutex_unlock, + tcondvar_new, + tcondvar_free, + tcondvar_wait, + tcondvar_wait_timeout, + tcondvar_wake_one, + tcondvar_wake_all +}; + +static DBusMutex * +tmutex_new (void) +{ + int *tmutex; + + tmutex = malloc (sizeof (int*)); + *tmutex = 0; + + return (DBusMutex *)tmutex; +} + +static void +tmutex_free (DBusMutex *mutex) +{ + free (mutex); +} + +static dbus_bool_t +tmutex_lock (DBusMutex *mutex) +{ + int *tmutex = (int *)mutex; + + _dbus_assert (*tmutex == 0); + + *tmutex = 1; + + return TRUE; +} + +static dbus_bool_t +tmutex_unlock (DBusMutex *mutex) +{ + int *tmutex = (int *)mutex; + + _dbus_assert (*tmutex == 1); + + *tmutex = 0; + + return TRUE; +} + +static DBusCondVar* +tcondvar_new (void) +{ + return (DBusCondVar*)0xcafebabe; +} + +static void +tcondvar_free (DBusCondVar *cond) +{ +} + +static void +tcondvar_wait (DBusCondVar *cond, + DBusMutex *mutex) +{ + int *tmutex = (int *)mutex; + + _dbus_assert (*tmutex == 1); +} + +static dbus_bool_t +tcondvar_wait_timeout (DBusCondVar *cond, + DBusMutex *mutex, + int timeout_msec) +{ + int *tmutex = (int *)mutex; + + _dbus_assert (*tmutex == 1); + + return TRUE; +} + + +static void +tcondvar_wake_one (DBusCondVar *cond) +{ +} + +static void +tcondvar_wake_all (DBusCondVar *cond) +{ +} + +void +debug_threads_init (void) +{ + dbus_threads_init (&functions); +} + -- cgit