Changeset 3606

Show
Ignore:
Timestamp:
07/24/08 11:11:18 (4 months ago)
Author:
ksprotte
Message:

allocate-in-area now gives up after 10ms

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/projects/bos/m2/allocation.lisp

    r3598 r3606  
    343343               (and (in-polygon-p x y (allocation-area-vertices area)) 
    344344                    (not (m2-contract (ensure-m2 x y)))))) 
    345       (dotimes (i 10) 
    346         (let ((x (+ area-left (random area-width))) 
    347               (y (+ area-top (random area-height))))           
    348           (when (allocatable-p x y) 
    349             (let ((result (try-allocation n x y #'allocatable-p))) 
    350               (when result 
    351                 (assert (alexandria:setp result :test #'equal)) 
    352                 (assert (= n (length result))) 
    353                 (decf (allocation-area-free-m2s area) n) 
    354                 (return-from allocate-in-area 
    355                   (mapcar (lambda (x-y) 
    356                             (destructuring-bind (x y) 
    357                                 x-y 
    358                               (ensure-m2 x y))) 
    359                           result)))))))))) 
     345      (loop with start-time = (get-internal-real-time) 
     346         do (let ((x (+ area-left (random area-width))) 
     347                  (y (+ area-top (random area-height))))           
     348              (when (allocatable-p x y) 
     349                (let ((result (try-allocation n x y #'allocatable-p))) 
     350                  (when result 
     351                    (assert (alexandria:setp result :test #'equal)) 
     352                    (assert (= n (length result))) 
     353                    (decf (allocation-area-free-m2s area) n) 
     354                    (return-from allocate-in-area 
     355                      (mapcar (lambda (x-y) 
     356                                (destructuring-bind (x y) 
     357                                    x-y 
     358                                  (ensure-m2 x y))) 
     359                              result)))))) 
     360         when (> (- (get-internal-real-time) start-time) 
     361                 ;; give up after 10 ms 
     362                 (* (/ 10 1000) internal-time-units-per-second)) 
     363         return nil)))) 
    360364 
    361365(defun allocate-m2s-for-sale (n)