Currently DBusWatcher registers read and write watchers on
the I/O thread unconditionally. Thus for read-only DBusWatch
structures, the write watcher on the I/O thread generates a
significant amount of CPU overhead by constantly reporting
success via calls to OnFileCanWriteWithoutBlocking.
This patch changes DBusWatcher to respect the status flags
of supplied DBusWatch structures. It will only poll for
read or write status if the DBus watch has the corresponding
flag set.
DBus keeps track of these flags and calls the toggle callback
when it needs to wait on a certain DBusWatch.
This patch converts DBusWatcher to run on the I/O thread. When a
caller starts DBus, StartDBus creates a new connection and adds
it to the I/O thread's poll loop. DBusWatchers are created and
removed automatically by the DBus libary.
The I/O thread provides all features of the DBus thread. So most
of the existing code has been removed or rewritten. The former
includes the control socket and the DBus thread, the latter is in
the DBusWatcher code.
Bluetooth maintains two connections to the DBus server and the DBus
system itself maintains a third one. This implies some overhead and
makes the code more difficult to understand.
This patch changes the Bluetooth code to use the connection that is
established by the DBus system.
DBusWatcher::Poll currently breaks after reading DBus data from the
socket. Thus, it never processes the data and dispatches the DBus
messages. This patch fixes the code to dispatch DBus messages after
reading the DBus socket.
This patch changes the DBus shutdown to only cleanup the DBus
thread from the main thread after DBusWatcher has completed.
This should ensure that the main thread will not have to wait
for the DBus thread.
--HG--
extra : rebase_source : 09ebb40a4e515ef5b0ebddfc1c3b7187cc546313
PollFdComparator, DBusEventTypes and flag conversion are only used by
DBusWatcher. This patch moves them into DBusWatcher's namespace.
--HG--
extra : rebase_source : 688403e55e139440e6d6d28e9802f8a48d7c355d
The Stop method encapsulates the code for sending the exit command
to a running DBus watcher.
--HG--
extra : rebase_source : 6963e6fa60b2e1e725046672a45cd325fc40a836
The DBus poll functionality is actually part of DBusWatcher. This
patch moves it to a class method.
--HG--
extra : rebase_source : 012813cf1d0967d6c29f7e085e49940570e1d58d
This patch renames DBusThread to DBusWatcher to make its purpose
more clear. Several callback functions for DBus are converted to
methods of DBusWatcher. Their POSIX calls are now protected by
TEMP_FAILURE_RETRY.
--HG--
extra : rebase_source : d8c6963aa8388c462917180d78e8e4289f9e987a
For replacing the Bluetooth command thread with a LazyIdleThread,
we need to make sure that the DBus service thread is shutdown from
within the main thread.
This patch changes the DBus stop code to cleanup the DBusThread
structure from the service thread to prevent race conditions during
shutdown. The DBus service thread itself gets shutdown from the main
thread to fulfill the requirements of LazyIdleThread. The patch also
makes sure that it's not possible to accidently dispatch a runnable
while the DBus thread terminates.
Instances of RawDBusConnection can now be contained in nsRefPtr. This
allows to share the DBus connection among multiple threads.
--HG--
extra : rebase_source : fb24472b3b55e77abc7354f17ef679661f62b7fb
The new function allows to schedule nsRunnables to an existing DBus
thread. This intercepts the running instance of DBusPollTask and
makes the DBus thread process the dispatched runnable. The intercepted
poll task automatically continues polling once all pending runnables
have been processed.
This patch replaces the DBus EventLoop function by an instance
of DBusPollTask. It also cleans up the initialization and shutdown
code of the DBusThread.
This patch adds class DBusPollTask. The DBusPollTask class is an
nsRunnable for receiving DBus messages. It is intended to run in
a separate thread that is dedicated to DBus only.
The Run function of the poll task resembles the DBus EventLoop
function, but allows to intercept execution in favor of other
nsRunnables. Afterwards the DBusPollTask continues.
We intent to run the DBus thread's EventLoop function as separate
nsRunnable, but the function also contains code for initializing
sockets that are used for internal communication.
With this patch the socket initialization has been moved to the
setup function. This reduces the EventLoop function to plain event
handling.