From d7f3187c2ec6f1290dd8471b425b814201ae8810 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Sun, 29 Jul 2018 11:59:21 +0200 Subject: [PATCH] Improve vc-mutex use * lisp/files.el (find-file-with-threads): Don't lock `vc-mutex' here ... (find-file-noselect): ... but here when wildcards are enabled. * lisp/vc/vc-hooks.el (vc-refresh-state): Lock `vc-mutex' only at thread start. Use buffer name as thread name. --- lisp/files.el | 18 +++---- lisp/vc/vc-hooks.el | 123 ++++++++++++++++++++++---------------------- 2 files changed, 69 insertions(+), 72 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index 128648ff316..195694a7b67 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -1591,12 +1591,7 @@ If WILDCARDS is non-nil, return the spec ( t )." (declare (indent 2) (debug t)) `(if ,async (progn - (make-thread - ;; We use `vc-mutex' here in order to let all - ;; `vc-refresh-state' run after the file visiting - ;; operations. - (lambda () (with-mutex vc-mutex ,@body)) - (concat "find-file " ,filename)) + (make-thread (lambda () ,@body) (concat "find-file " ,filename)) (thread-yield)) ,@body)) @@ -2216,10 +2211,13 @@ every file will be loaded in an own thread." (lambda () (find-file-noselect file)) (concat "find-file-noselect " file))) files)) - ;; Collect the results. - (thread-yield) - (dolist (thread threads result) - (setq result (cons (thread-join thread) result)))) + ;; Collect the results. We use `vc-mutex' here in + ;; order to let all `vc-refresh-state' threads run + ;; after the file visiting operations. + (with-mutex vc-mutex + (thread-yield) + (dolist (thread threads result) + (setq result (cons (thread-join thread) result))))) (mapcar #'find-file-noselect files)))) diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el index 1d572c10f49..59c66e77bb4 100644 --- a/lisp/vc/vc-hooks.el +++ b/lisp/vc/vc-hooks.el @@ -814,70 +814,69 @@ In the latter case, VC mode is deactivated for this buffer." ;; Run it asynchronously. (make-thread (lambda () - ;; Don't let the vc operations disturb each other. Delay this - ;; after all find-file* operations have finished. - (with-mutex vc-mutex - (vc-file-clearprops buffer-file-name) - ;; FIXME: Why use a hook? Why pass it buffer-file-name? - (add-hook 'vc-mode-line-hook 'vc-mode-line nil t) - (let (backend) - (cond - ((setq backend (with-demoted-errors (vc-backend buffer-file-name))) - ;; Let the backend setup any buffer-local things he needs. - (vc-call-backend backend 'find-file-hook) - ;; Compute the state and put it in the mode line. - (vc-mode-line buffer-file-name backend) - (unless vc-make-backup-files - ;; Use this variable, not make-backup-files, - ;; because this is for things that depend on the file name. - (set (make-local-variable 'backup-inhibited) t))) - ((let* ((truename (and buffer-file-truename - (expand-file-name buffer-file-truename))) - (link-type (and truename - (not (equal buffer-file-name truename)) - (vc-backend truename)))) - (cond ((not link-type) nil) ;Nothing to do. - ((eq vc-follow-symlinks nil) + ;; Wait, until the file visitng function tells us so. + (with-mutex vc-mutex) + (vc-file-clearprops buffer-file-name) + ;; FIXME: Why use a hook? Why pass it buffer-file-name? + (add-hook 'vc-mode-line-hook 'vc-mode-line nil t) + (let (backend) + (cond + ((setq backend (with-demoted-errors (vc-backend buffer-file-name))) + ;; Let the backend setup any buffer-local things he needs. + (vc-call-backend backend 'find-file-hook) + ;; Compute the state and put it in the mode line. + (vc-mode-line buffer-file-name backend) + (unless vc-make-backup-files + ;; Use this variable, not make-backup-files, because this + ;; is for things that depend on the file name. + (set (make-local-variable 'backup-inhibited) t))) + ((let* ((truename (and buffer-file-truename + (expand-file-name buffer-file-truename))) + (link-type (and truename + (not (equal buffer-file-name truename)) + (vc-backend truename)))) + (cond ((not link-type) nil) ;Nothing to do. + ((eq vc-follow-symlinks nil) + (message + "Warning: symbolic link to %s-controlled source file" + link-type)) + ((or (not (eq vc-follow-symlinks 'ask)) + ;; Assume we cannot ask, default to yes. + noninteractive + ;; Copied from server-start. Seems like there + ;; should be a better way to ask "can we get + ;; user input?"... + (and (daemonp) + (null (cdr (frame-list))) + (eq (selected-frame) terminal-frame)) + ;; If we already visited this file by + ;; following the link, don't ask again if we + ;; try to visit it again. GUD does that, and + ;; repeated questions are painful. + (get-file-buffer + (abbreviate-file-name + (file-chase-links buffer-file-name)))) + + (vc-follow-link) + (message "Followed link to %s" buffer-file-name) + (vc-refresh-state)) + (t + (if (yes-or-no-p + (format + (concat + "Symbolic link to %s-controlled source file; " + "follow link? ") + link-type)) + (progn (vc-follow-link) + (message + "Followed link to %s" buffer-file-name) + (vc-refresh-state)) (message - "Warning: symbolic link to %s-controlled source file" - link-type)) - ((or (not (eq vc-follow-symlinks 'ask)) - ;; Assume we cannot ask, default to yes. - noninteractive - ;; Copied from server-start. Seems like - ;; there should be a better way to ask "can - ;; we get user input?"... - (and (daemonp) - (null (cdr (frame-list))) - (eq (selected-frame) terminal-frame)) - ;; If we already visited this file by - ;; following the link, don't ask again if we - ;; try to visit it again. GUD does that, - ;; and repeated questions are painful. - (get-file-buffer - (abbreviate-file-name - (file-chase-links buffer-file-name)))) - - (vc-follow-link) - (message "Followed link to %s" buffer-file-name) - (vc-refresh-state)) - (t - (if (yes-or-no-p - (format - (concat - "Symbolic link to %s-controlled source file; " - "follow link? ") - link-type)) - (progn (vc-follow-link) - (message - "Followed link to %s" buffer-file-name) - (vc-refresh-state)) - (message - (concat - "Warning: editing through the link " - "bypasses version control"))))))))))) + (concat + "Warning: editing through the link " + "bypasses version control")))))))))) ;; The thread name. - (concat "vc-refresh-state " buffer-file-name)) + (concat "vc-refresh-state " (buffer-name))) ;; Give other threads a chance to run. (thread-yield))) -- 2.39.5