emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

elisp test-and-set?


From: Stephen Leake
Subject: elisp test-and-set?
Date: Fri, 25 May 2018 16:00:04 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (windows-nt)

In ada-mode, I'm using a parser running in an external process to
compute faces and indentation.

Since faces are computed by font-lock, which runs on a timer in the
background, it can try to run when indent is running in the foreground.

So in the code that deals with the external process, I need mutual
exclusion; prevent font-lock from starting a new parse if a parse is
already running.

The code I currently have for that is:

  (if (wisi-process--parser-busy parser)
      (error "%s parse abandoned; parser busy" wisi--parse-action)

    (setf (wisi-process--parser-busy parser) t)
    ... more parsing stuff
    )

There is a tiny window of time when this can fail; if font-lock and
foreground both execute the "if" condition 'simultaneously' (ie, before
the other sets busy t), both will go on to parse.

In other contexts I'd use a "test and set" instruction for this; read
the flag and set it true in one uninterruptible action. I don't see
anything like that in elisp, and searching in the elisp manual for
"mutual" and "exclusion" is no help.

I also don't see "font-lock-inhibit", which could be useful here, but would
probably have the same race condition.

Is there a way to do this right?

-- 
-- Stephe



reply via email to

[Prev in Thread] Current Thread [Next in Thread]