unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* elisp test-and-set?
@ 2018-05-25 21:00 Stephen Leake
  2018-05-26  0:38 ` Noam Postavsky
  2018-05-26  7:08 ` Eli Zaretskii
  0 siblings, 2 replies; 5+ messages in thread
From: Stephen Leake @ 2018-05-25 21:00 UTC (permalink / raw)
  To: emacs-devel

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-05-26 21:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-25 21:00 elisp test-and-set? Stephen Leake
2018-05-26  0:38 ` Noam Postavsky
2018-05-26  7:08 ` Eli Zaretskii
2018-05-26  7:53   ` Stephen Leake
2018-05-26 21:14   ` Stefan Monnier

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).