- (declare (optimize (speed 3) (safety 0))
- #!-sb-thread (ignore spinlock))
- ;; %instance-set-conditional cannot compare arbitrary objects
- ;; meaningfully, so
- ;; (sb!vm::%instance-set-conditional spinlock 2 our-value 0)
- ;; does not work for bignum thread ids.
- #!+sb-thread
- (sb!vm::%instance-set spinlock 2 0))
-
-(defmacro with-spinlock ((spinlock) &body body)
- (sb!int:with-unique-names (lock got-it)
- `(let ((,lock ,spinlock)
- (,got-it nil))
- (unwind-protect
- (progn
- (setf ,got-it (get-spinlock ,lock))
- (locally ,@body))
- (when ,got-it
- (release-spinlock ,lock))))))