(aref heap 0)))
(defun heap-extract (heap i &key (key #'identity) (test #'>=))
- (when (< (length heap) i)
+ (unless (> (length heap) i)
(error "Heap underflow"))
(prog1
(aref heap i)
;; FUNCTION until the other is called, from when it does nothing.
(let ((mutex (sb!thread:make-mutex))
(cancelled-p nil))
- #!-sb-thread
- (declare (ignore mutex))
(list
#'(lambda ()
(sb!thread:with-recursive-lock (mutex)
(defvar *scheduler-lock* (sb!thread:make-mutex :name "Scheduler lock"))
(defmacro with-scheduler-lock ((&optional) &body body)
- ;; don't let the SIGALRM handler mess things up
- `(sb!thread::call-with-system-mutex (lambda () ,@body) *scheduler-lock*))
+ ;; Don't let the SIGALRM handler mess things up.
+ `(sb!thread::with-system-mutex (*scheduler-lock*)
+ ,@body))
(defun under-scheduler-lock-p ()
#!-sb-thread
;;; Not public, but related
(defun reschedule-timer (timer)
- (with-scheduler-lock ()
- (setf (%timer-expire-time timer) (+ (get-internal-real-time)
- (%timer-repeat-interval timer)))
- (%schedule-timer timer)))
+ (let ((thread (%timer-thread timer)))
+ (if (and (sb!thread::thread-p thread) (not (sb!thread:thread-alive-p thread)))
+ (unschedule-timer timer)
+ (with-scheduler-lock ()
+ (setf (%timer-expire-time timer) (+ (get-internal-real-time)
+ (%timer-repeat-interval timer)))
+ (%schedule-timer timer)))))
;;; Expiring timers