Changeset 10775


Ignore:
Timestamp:
Sep 16, 2008, 9:06:00 PM (11 years ago)
Author:
gz
Message:

fix for looking up (as opposed to puthashing) marker values (broken by recent change to nhash.find). Some tweaks to comments/indentation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/level-0/l0-hash.lisp

    r10751 r10775  
    2020;;
    2121;; See hash.lisp for documentation
    22 ;; Five bits in the nhash.vector.flags fixnum interact with the garbage
    23 ;; collector.  This description uses the symbols that represent bit numbers
    24 ;; in a fixnum.  $nhash_xxx_bit has a corresponding $nhash_lap_xxx_bit which
    25 ;; gives the byte offset of the bit for LAP code.  The two bytes in
    26 ;; question are at offsets $nhash.vector-weak-byte and
    27 ;; $nhash.vector-track-keys-byte offsets from the tagged vector.
    28 ;; The 32 bits of the fixnum at nhash.vector.flags look like:
    29 ;;
    30 ;;     TK0C0000 00000000 WVF00000 00000000
    31 ;;
    32 ;;
    33 ;; $nhash_track_keys_bit         "T" in the diagram above
    34 ;;                               Sign bit of the longword at $nhash.vector.flags
    35 ;;                               or the byte at $nhash.vector-track-keys-byte.
    36 ;;                               If set, GC tracks relocation of keys in the
    37 ;;                               vector.
    38 ;; $nhash_key_moved_bit          "K" in the diagram above
    39 ;;                               Set by GC to indicate that a key moved.
    40 ;;                               If $nhash_track_keys_bit is clear, this bit is set to
    41 ;;                               indicate that any GC will require a rehash.
    42 ;;                               GC never clears this bit, but may set it if
    43 ;;                               $nhash_track_keys_bit is set.
    44 ;; $nhash_component_address_bit  "C" in the diagram above.
    45 ;;                               Ignored by GC.  Set to indicate that the
    46 ;;                               address of a component of a key was used.
    47 ;;                               Means that $nhash_track_keys_bit will
    48 ;;                               never be set until all such keys are
    49 ;;                               removed.
    50 ;; $nhash_weak_bit               "W" in the diagram above
    51 ;;                               Sign bit of the byte at $nhash.vector-weak-byte
    52 ;;                               Set to indicate a weak hash table
    53 ;; $nhash_weak_value_bit         "V" in the diagram above
    54 ;;                               If clear, the table is weak on key
    55 ;;                               If set, the table is weak on value
    56 ;; $nhash_finalizeable_bit       "F" in the diagram above
    57 ;;                               If set the table is finalizeable:
    58 ;;                               If any key/value pairs are removed, they will be added to
    59 ;;                               the nhash.vector.finalization-alist using cons cells
    60 ;;                               from nhash.vector.free-alist
    61 
    62 
    63 
    6422
    6523
     
    156114      ;; GC is not tracking key movement
    157115      (if (logbitp $nhash_component_address_bit flags)
    158          (not (eql (the fixnum (%get-gc-count)) (the fixnum (nhash.vector.gc-count vector))))))))
     116        (not (eql (the fixnum (%get-gc-count)) (the fixnum (nhash.vector.gc-count vector))))))))
    159117
    160118(defun %set-does-not-need-rehashing (hash)
     
    773731(defun lock-free-puthash (key hash value)
    774732  (declare (optimize (speed 3) (safety 0) (debug 0)))
    775   (when (eq key free-hash-marker)
    776     (error "Can't use ~s as a hash-table key" key))
    777733  (when (or (eq value rehashing-value-marker)
    778734            (eq value free-hash-marker))
     
    836792  (unless (typep hash 'hash-table)
    837793    (report-bad-arg hash 'hash-table))
     794  (when (or (eq key free-hash-marker)
     795            (eq key deleted-hash-key-marker))
     796    (return-from gethash (values default nil)))
    838797  (when (hash-lock-free-p hash)
    839798    (return-from gethash (lock-free-gethash key hash default)))
     
    979938  (unless (typep hash 'hash-table)
    980939    (report-bad-arg hash 'hash-table))
     940  (when (or (eq key free-hash-marker)
     941            (eq key deleted-hash-key-marker))
     942    (error "Can't use ~s as a hash-table key" key))
    981943  (when (hash-lock-free-p hash)
    982944    (return-from puthash (lock-free-puthash key hash value)))
    983   (if (eq key free-hash-marker)
    984     (error "Can't use ~s as a hash-table key" key))
    985945  (with-lock-context
    986946    (without-interrupts
     
    10671027           (flags 0)
    10681028           (flags-sans-weak 0)
    1069            (weak-flags 0))
    1070       (declare (fixnum old-total-size flags flags-sans-weak weak-flags))   
     1029           (weak-flags nil))
     1030      (declare (fixnum old-total-size flags flags-sans-weak))
    10711031      (when (> (nhash.vector.deleted-count old-vector) 0)
    10721032        ;; There are enough deleted entries. Rehash to get rid of them
     
    10881048              (%normalize-hash-table-count hash)
    10891049              (when (> (nhash.vector.deleted-count old-vector) 0)
     1050                (setf (nhash.vector.flags old-vector) flags)
     1051                (setq weak-flags nil)
    10901052                (return-from grow-hash-table (%rehash hash)))
    10911053              (setq vector (%cons-nhash-vector total-size 0))
     
    11101072                     (nhash.vector.count vector) old-size
    11111073                     (nhash.vector.flags vector)
    1112                      (logior weak-flags (the fixnum (nhash.vector.flags vector))))
     1074                     (logior (the fixnum weak-flags)
     1075                             (the fixnum (nhash.vector.flags vector))))
    11131076               (setf (nhash.rehash-bits hash) nil
    11141077                     (nhash.vector hash) vector
     
    11241087            (when weak-flags
    11251088              (setf (nhash.vector.flags old-vector)
    1126                     (logior weak-flags (the fixnum (nhash.vector.flags old-vector)))))))))))
     1089                    (logior (the fixnum weak-flags)
     1090                            (the fixnum (nhash.vector.flags old-vector)))))))))))
    11271091
    11281092
     
    12801244          (setq table-key (%svref vector vector-index))
    12811245          (when (= vector-index initial-index)
    1282             (or first-deleted-index
    1283                 (error "Bug: no deleted entries in table")))
     1246            (return (or first-deleted-index
     1247                        (error "Bug: no deleted entries in table"))))
    12841248          (if (eq table-key key)
    12851249            (return vector-index)
     
    18781842                 (lock-free-enumerate-hash-keys-and-values hash keys values)))
    18791843  (with-lock-context
    1880       (without-interrupts
    1881        (let* ((readonly (eq (read-lock-hash-table hash) :readonly)))
    1882          (do* ((in (nhash.vector hash))
    1883                (in-idx $nhash.vector_overhead (+ in-idx 2))
    1884                (insize (uvsize in))
    1885                (outsize (length (or keys values)))
    1886                (out-idx 0))
    1887               ((or (= in-idx insize)
    1888                    (= out-idx outsize))
    1889                (unlock-hash-table hash readonly)
    1890                out-idx)
    1891            (declare (fixnum in-idx insize out-idx outsize))
    1892            (let* ((key (%svref in in-idx)))
    1893              (unless (or (eq key free-hash-marker)
    1894                          (eq key deleted-hash-key-marker))
    1895                (when keys
    1896                  (setf (%svref keys out-idx) key))
    1897                (when values
    1898                  (setf (%svref values out-idx) (%svref in (%i+ in-idx 1))))
    1899                (incf out-idx))))))))
    1900  
     1844    (without-interrupts
     1845     (let* ((readonly (eq (read-lock-hash-table hash) :readonly)))
     1846       (do* ((in (nhash.vector hash))
     1847             (in-idx $nhash.vector_overhead (+ in-idx 2))
     1848             (insize (uvsize in))
     1849             (outsize (length (or keys values)))
     1850             (out-idx 0))
     1851           ((or (= in-idx insize)
     1852                (= out-idx outsize))
     1853              (unlock-hash-table hash readonly)
     1854              out-idx)
     1855         (declare (fixnum in-idx insize out-idx outsize))
     1856         (let* ((key (%svref in in-idx)))
     1857           (unless (or (eq key free-hash-marker)
     1858                       (eq key deleted-hash-key-marker))
     1859             (when keys
     1860               (setf (%svref keys out-idx) key))
     1861             (when values
     1862               (setf (%svref values out-idx) (%svref in (%i+ in-idx 1))))
     1863             (incf out-idx))))))))
     1864
    19011865(defun enumerate-hash-keys (hash out)
    19021866  (enumerate-hash-keys-and-values hash out nil))
Note: See TracChangeset for help on using the changeset viewer.