* successful adds. i.e. if #FALSE is returned the net result
* should be that dbus_connection_set_watch_functions() has no effect,
* but the add_function and remove_function may have been called.
+ *
+ * @todo We need to drop the lock when we call the
+ * add/remove/toggled functions which can be a side effect
+ * of setting the watch functions.
*
* @param connection the connection.
* @param add_function function to begin monitoring a new descriptor.
dbus_mutex_lock (connection->mutex);
/* ref connection for slightly better reentrancy */
_dbus_connection_ref_unlocked (connection);
-
+
+ /* FIXME this can call back into user code, and we need to drop the
+ * connection lock when it does.
+ */
retval = _dbus_watch_list_set_functions (connection->watches,
add_function, remove_function,
toggled_function,
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-threads.h D-BUS threads handling
*
- * Copyright (C) 2002 Red Hat Inc.
+ * Copyright (C) 2002, 2003 Red Hat Inc.
*
* Licensed under the Academic Free License version 1.2
*
static int thread_init_generation = 0;
/** This is used for the no-op default mutex pointer, just to be distinct from #NULL */
-#ifdef DBUS_BUILD_TESTS
-#define _DBUS_DUMMY_MUTEX_NEW ((DBusMutex*)_dbus_strdup ("FakeMutex"))
-#else
-#define _DBUS_DUMMY_MUTEX_NEW ((DBusMutex*)0xABCDEF)
-#endif
+#define _DBUS_DUMMY_MUTEX ((DBusMutex*)0xABCDEF)
/** This is used for the no-op default mutex pointer, just to be distinct from #NULL */
-#ifdef DBUS_BUILD_TESTS
-#define _DBUS_DUMMY_CONDVAR_NEW ((DBusCondVar*)_dbus_strdup ("FakeCondvar"))
-#else
-#define _DBUS_DUMMY_CONDVAR_NEW ((DBusCondVar*)0xABCDEF2)
-#endif
+#define _DBUS_DUMMY_CONDVAR ((DBusCondVar*)0xABCDEF2)
/**
* @defgroup DBusThreads Thread functions
if (thread_functions.mutex_new)
return (* thread_functions.mutex_new) ();
else
- return _DBUS_DUMMY_MUTEX_NEW;
+ return _DBUS_DUMMY_MUTEX;
}
/**
{
if (mutex && thread_functions.mutex_free)
(* thread_functions.mutex_free) (mutex);
-#ifdef DBUS_BUILD_TESTS
- /* Free the fake mutex */
- else
- dbus_free (mutex);
-#endif
}
/**
if (thread_functions.condvar_new)
return (* thread_functions.condvar_new) ();
else
- return _DBUS_DUMMY_CONDVAR_NEW;
+ return _DBUS_DUMMY_CONDVAR;
}
/**
{
if (cond && thread_functions.condvar_free)
(* thread_functions.condvar_free) (cond);
-#ifdef DBUS_BUILD_TESTS
- else
- /* Free the fake condvar */
- dbus_free (cond);
-#endif
}
/**
return TRUE;
}
+
+#ifdef DBUS_BUILD_TESTS
+/** Fake mutex used for debugging */
+typedef struct DBusFakeMutex DBusFakeMutex;
+/** Fake mutex used for debugging */
+struct DBusFakeMutex
+{
+ dbus_bool_t locked; /**< Mutex is "locked" */
+};
+
+static DBusMutex * dbus_fake_mutex_new (void);
+static void dbus_fake_mutex_free (DBusMutex *mutex);
+static dbus_bool_t dbus_fake_mutex_lock (DBusMutex *mutex);
+static dbus_bool_t dbus_fake_mutex_unlock (DBusMutex *mutex);
+static DBusCondVar* dbus_fake_condvar_new (void);
+static void dbus_fake_condvar_free (DBusCondVar *cond);
+static void dbus_fake_condvar_wait (DBusCondVar *cond,
+ DBusMutex *mutex);
+static dbus_bool_t dbus_fake_condvar_wait_timeout (DBusCondVar *cond,
+ DBusMutex *mutex,
+ int timeout_msec);
+static void dbus_fake_condvar_wake_one (DBusCondVar *cond);
+static void dbus_fake_condvar_wake_all (DBusCondVar *cond);
+
+
+static const DBusThreadFunctions fake_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_fake_mutex_new,
+ dbus_fake_mutex_free,
+ dbus_fake_mutex_lock,
+ dbus_fake_mutex_unlock,
+ dbus_fake_condvar_new,
+ dbus_fake_condvar_free,
+ dbus_fake_condvar_wait,
+ dbus_fake_condvar_wait_timeout,
+ dbus_fake_condvar_wake_one,
+ dbus_fake_condvar_wake_all
+};
+
+static DBusMutex *
+dbus_fake_mutex_new (void)
+{
+ DBusFakeMutex *mutex;
+
+ mutex = dbus_new0 (DBusFakeMutex, 1);
+
+ return (DBusMutex *)mutex;
+}
+
+static void
+dbus_fake_mutex_free (DBusMutex *mutex)
+{
+ DBusFakeMutex *fake = (DBusFakeMutex*) mutex;
+
+ _dbus_assert (!fake->locked);
+
+ dbus_free (fake);
+}
+
+static dbus_bool_t
+dbus_fake_mutex_lock (DBusMutex *mutex)
+{
+ DBusFakeMutex *fake = (DBusFakeMutex*) mutex;
+
+ _dbus_assert (!fake->locked);
+
+ fake->locked = TRUE;
+
+ return TRUE;
+}
+
+static dbus_bool_t
+dbus_fake_mutex_unlock (DBusMutex *mutex)
+{
+ DBusFakeMutex *fake = (DBusFakeMutex*) mutex;
+
+ _dbus_assert (fake->locked);
+
+ fake->locked = FALSE;
+
+ return TRUE;
+}
+
+static DBusCondVar*
+dbus_fake_condvar_new (void)
+{
+ return (DBusCondVar*) _dbus_strdup ("FakeCondvar");
+}
+
+static void
+dbus_fake_condvar_free (DBusCondVar *cond)
+{
+ dbus_free (cond);
+}
+
+static void
+dbus_fake_condvar_wait (DBusCondVar *cond,
+ DBusMutex *mutex)
+{
+
+}
+
+static dbus_bool_t
+dbus_fake_condvar_wait_timeout (DBusCondVar *cond,
+ DBusMutex *mutex,
+ int timeout_msec)
+{
+ return TRUE;
+}
+
+static void
+dbus_fake_condvar_wake_one (DBusCondVar *cond)
+{
+
+}
+
+static void
+dbus_fake_condvar_wake_all (DBusCondVar *cond)
+{
+
+}
+
+dbus_bool_t
+_dbus_threads_init_debug (void)
+{
+ return dbus_threads_init (&fake_functions);
+}
+
+#endif /* DBUS_BUILD_TESTS */
+
/** @} */