]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve vc-mutex use
authorMichael Albinus <michael.albinus@gmx.de>
Sun, 29 Jul 2018 09:59:21 +0000 (11:59 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Sat, 4 Aug 2018 10:31:58 +0000 (12:31 +0200)
* 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
lisp/vc/vc-hooks.el

index 128648ff3165c14808d9465204047d80f9ed8147..195694a7b67c60e511821fd2badefa9bdc4db664 100644 (file)
@@ -1591,12 +1591,7 @@ If WILDCARDS is non-nil, return the spec (<filename> t <async>)."
   (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))))
 
index 1d572c10f4900fbe6328ab1d5b856b895add4afb..59c66e77bb4a9129f58e012528192635cae55f8a 100644 (file)
@@ -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)))