unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Albinus <michael.albinus@gmx.de>
To: Daniel Colascione <dancol@dancol.org>
Cc: 16775@debbugs.gnu.org
Subject: bug#16775: dbus interacts poorly with lisp-level event loops
Date: Mon, 17 Feb 2014 14:27:04 +0100	[thread overview]
Message-ID: <87k3ctg993.fsf@gmx.de> (raw)
In-Reply-To: <5301EFB0.7000400@dancol.org> (Daniel Colascione's message of "Mon, 17 Feb 2014 03:17:04 -0800")

Daniel Colascione <dancol@dancol.org> writes:

> dbus-call-method expects read-event to return the dbus event
> immediately, but read_char in keyboard.c treats the dbus event as a
> special event and runs it through special-event-map itself before
> sitting and reading another event. The event waiting loop always times
> out, so dbus-call-method always takes at least 100ms due to the
> hard-coded 0.1 timeout parameter to read-event.

dbus-call-method does not expect the D-Bus event to be returned by
read-event. It simply calls read-event in order to trigger event
handling. The loop itself checks, whether the respective event has been
inserted into dbus-return-values-table. And when *other* but D-Bus events
do arrive in the meantime, they must be preserved in unread-command-events.

Why is it a problem to wait at least 100ms? D-Bus messages are not
expected to perform in real time (whatever this means).

> This problem is hairy: special-event-map functions can execute arbitrary
> code and re-enter the dbus synchronous event loop, and there's no way to
> non-locally terminate a particular read-event loop. Here's the
> problematic scenario: dbus-call-method works by setting up an
> asynchronous dbus call and calling read-event until the specific
> asynchronous call on which it is waiting completes.

Why do you want to terminate non-locally in dbus-call-method? If you
need asynchronous behaviour, there is dbus-call-method-asynchronously.

> The immediate problem is that read-event never actually returns because
> the dbus event is special

As said above this is not a problem but intended.

> --- but let's say we worked around that
> problem by modifying special-event-map around the read-event call so
> that read-event returned immediately. We'd still have a serious issue
> because *other*, non-dbus special event handles can run arbitrary code
> and enter an inner dbus-call-method reply-waiting loop. If the reply to
> the outer synchronous dbus call arrives before the reply to the inner
> synchronous dbus call, dbus-call-method-handler (which is run from
> special-event-map inside read-event or, in our hypothetical partial fix,
> manually from the wait loop) will dutifully put the reply on
> dbus-return-values-table. But the inner event loop has no way of waking
> the *outer* event loop, so when the special event handler that called
> the inner dbus-call-method returns, read_char will loop around and wait
> for the full timeout period before returning to the outer dbus-call-method.

I don't understand the scenario. Could you, please, give a code example?

> If dbus had been implemented as a process type instead of a special
> event source, we'd just be able to use accept-process-output in dbus-call.

There is already the discussion that such events (dbus, file
notification) should be implemented differently. I don't know whether
this shall be done as process type or as a separate queue to be checked for.

Best regards, Michael.





  reply	other threads:[~2014-02-17 13:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <5301EAE0.5080008@dancol.org>
2014-02-17 11:17 ` bug#16775: dbus interacts poorly with lisp-level event loops Daniel Colascione
2014-02-17 13:27   ` Michael Albinus [this message]
2014-02-17 13:52     ` Daniel Colascione
2014-02-17 15:07       ` Michael Albinus
2014-02-17 15:22         ` Daniel Colascione
2014-02-17 15:57           ` Michael Albinus
2014-03-26 13:10             ` Michael Albinus
2016-12-13  0:15               ` Glenn Morris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k3ctg993.fsf@gmx.de \
    --to=michael.albinus@gmx.de \
    --cc=16775@debbugs.gnu.org \
    --cc=dancol@dancol.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).