[slime-cvs] CVS slime

CVS User nsiivola nsiivola at common-lisp.net
Sat Jun 18 11:51:22 UTC 2011


Update of /project/slime/cvsroot/slime
In directory common-lisp.net:/tmp/cvs-serv20168

Modified Files:
	ChangeLog swank.lisp 
Log Message:
swank: lock around updating the indentation cache

  Hash-tables aren't necessarily thread safe. (Yes, I actually
  saw the table get corrupted -- this isn't just theoretical.)


--- /project/slime/cvsroot/slime/ChangeLog	2011/06/16 08:29:17	1.2203
+++ /project/slime/cvsroot/slime/ChangeLog	2011/06/18 11:51:22	1.2204
@@ -1,3 +1,12 @@
+2011-06-18  Nikodemus Siivola  <nikodemus at random-state.net>
+
+	* swank.lisp (*indentation-cache-lock*): New variable:
+	hash-table updates aren't necessarily thread-safe.
+	(perform-indentation-update, update-indentation/delta-for-emacs):
+	Grab the lock when necessary -- in delta-for-emacs we hold on to
+	it a bit longer than necessary, but the code is easier to read
+	this way.
+
 2011-06-16  Nikodemus Siivola  <nikodemus at random-state.net>
 
 	* swank.lisp (macro-indentation): Restore the old simple version.
--- /project/slime/cvsroot/slime/swank.lisp	2011/06/16 08:29:17	1.748
+++ /project/slime/cvsroot/slime/swank.lisp	2011/06/18 11:51:22	1.749
@@ -3867,6 +3867,10 @@
   "When true, automatically send indentation information to Emacs
 after each command.")
 
+(defvar *indentation-cache-lock*
+  ;; Hash-tables aren't necessarily thread safe.
+  (make-lock :name "Indentation Cache Lock"))
+
 (defslimefun update-indentation-information ()
   (perform-indentation-update *emacs-connection* t)
   nil)
@@ -3889,7 +3893,9 @@
   "Update the indentation cache in CONNECTION and update Emacs.
 If FORCE is true then start again without considering the old cache."
   (let ((cache (connection.indentation-cache connection)))
-    (when force (clrhash cache))
+    (when force
+      (call-with-lock-held 
+       *indentation-cache-lock* (lambda () (clrhash cache))))
     (let ((delta (update-indentation/delta-for-emacs cache force)))
       (setf (connection.indentation-cache-packages connection)
             (list-all-packages))
@@ -3904,13 +3910,16 @@
     (flet ((consider (symbol)
              (let ((indent (symbol-indentation symbol)))
                (when indent
-                 (unless (equal (gethash symbol cache) indent)
-                   (setf (gethash symbol cache) indent)
-                   (let ((pkgs (loop for p in (list-all-packages)
-                                     when (eq symbol (find-symbol (string symbol) p))
-                                     collect (package-name p)))
-                         (name (string-downcase symbol)))
-                     (push (list name indent pkgs) alist)))))))
+                 (call-with-lock-held
+                  *indentation-cache-lock*
+                  (lambda ()
+                    (unless (equal (gethash symbol cache) indent)
+                      (setf (gethash symbol cache) indent)
+                      (let ((pkgs (loop for p in (list-all-packages)
+                                        when (eq symbol (find-symbol (string symbol) p))
+                                        collect (package-name p)))
+                            (name (string-downcase symbol)))
+                        (push (list name indent pkgs) alist)))))))))
       (if force
           (do-all-symbols (symbol)
             (consider symbol))





More information about the slime-cvs mailing list