Optimizations in with-lock: save reference to current process and use some fixnum comparisons.

This commit is contained in:
Juanjo Garcia-Ripoll 2013-10-28 00:00:38 +01:00
parent 312110ceca
commit 0ca6dbccbe

View file

@ -116,16 +116,20 @@ by ALLOW-WITH-INTERRUPTS."
;; the get-lock statement, to ensure that the unlocking is done with
;; interrupts disabled.
#+threads
(ext:with-unique-names (lock owner count)
(ext:with-unique-names (lock owner count process)
`(let* ((,lock ,lock-form)
(,owner (mp:lock-owner ,lock))
(,count (mp:lock-count ,lock)))
(declare (type fixnum ,count))
(without-interrupts
(unwind-protect
(with-restored-interrupts
(mp::get-lock ,lock)
(locally ,@body))
(when (and (eq mp:*current-process* (mp:lock-owner ,lock))
(or (not (eq ,owner mp:*current-process*))
(> (mp:lock-count ,lock) ,count)))
(mp::giveup-lock ,lock)))))))
(let ((,process mp:*current-process*))
(declare (optimize (speed 3) (safety 0) (debug 0)))
(when (and (eq ,process (mp:lock-owner ,lock))
(or (not (eq ,owner ,process))
(> (the fixnum (mp:lock-count ,lock))
(the fixnum ,count))))
(mp::giveup-lock ,lock))))))))