Function: with-tramp-locked-connection
with-tramp-locked-connection is a macro defined in tramp.el.gz.
Signature
(with-tramp-locked-connection PROC &rest BODY)
Documentation
Lock PROC for other communication, and run BODY.
Mostly useful to protect BODY from being interrupted by timers.
Source Code
;; Defined in /usr/src/emacs/lisp/net/tramp.el.gz
;;; Utility functions:
;; In Emacs, there is some concurrency due to timers. If a timer
;; interrupts Tramp and wishes to use the same connection buffer as
;; the "main" Emacs, then garbage might occur in the connection
;; buffer. Therefore, we need to make sure that a timer does not use
;; the same connection buffer as the "main" Emacs. We lock each
;; connection process separately by a connection property.
(defmacro with-tramp-locked-connection (proc &rest body)
"Lock PROC for other communication, and run BODY.
Mostly useful to protect BODY from being interrupted by timers."
(declare (indent 1) (debug t))
`(if (tramp-get-connection-property ,proc "locked")
;; Be kind for old versions of Emacs.
(if (member 'remote-file-error debug-ignored-errors)
(throw 'non-essential 'non-essential)
(tramp-error
,proc 'remote-file-error "Forbidden reentrant call of Tramp"))
(unwind-protect
(progn
(tramp-set-connection-property ,proc "locked" t)
,@body)
(tramp-flush-connection-property ,proc "locked"))))