Changeset 7742


Ignore:
Timestamp:
Nov 24, 2007, 6:35:25 PM (17 years ago)
Author:
Gary Byers
Message:

Locking, hash-table-iteration changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/working-0711/ccl/lib/macros.lisp

    r7681 r7742  
    23482348the lock held."
    23492349  (declare (ignore whostate))
    2350   `(with-lock-context
    2351     (with-recursive-lock (,lock) ,@body)))
     2350    (let* ((locked (gensym))
     2351           (l (gensym)))
     2352      `  (with-lock-context
     2353           (let ((,locked (make-lock-acquisition))
     2354             (,l ,lock))
     2355        (declare (dynamic-extent ,locked))
     2356        (unwind-protect
     2357             (progn
     2358               (%lock-recursive-lock-object ,l ,locked )
     2359               ,@body)
     2360          (when (lock-acquisition.status ,locked) (%unlock-recursive-lock-object ,l)))))))
    23522361
    23532362(defmacro with-lock-grabbed-maybe ((lock &optional
     
    23552364                                   &body body)
    23562365  (declare (ignore whostate))
    2357   `(with-lock-context
    2358     (with-recursive-lock-maybe (,lock) ,@body)))
     2366  (let* ((l (gensym)))
     2367    `(with-lock-context
     2368      (let* ((,l ,lock))
     2369        (when (%try-recursive-lock-object ,l)
     2370          (unwind-protect
     2371               (progn ,@body)
     2372            (%unlock-recursive-lock-object ,l)))))))
    23592373
    23602374(defmacro with-standard-abort-handling (abort-message &body body)
     
    26012615     nil))
    26022616
    2603 (defmacro with-hash-write-lock ((hash) &body body)
    2604   `(with-write-lock ((nhash.exclusion-lock ,hash))
    2605     ,@body))
    2606 
    2607 ;;; To ... er, um, ... expedite implementation, we lock the hash
    2608 ;;; table exclusively whenever touching it.  For now.
    2609 
    2610 (defmacro with-exclusive-hash-lock ((hash) &body body)
    2611   `(with-hash-write-lock (,hash) ,@body))
     2617
    26122618
    26132619(defmacro with-hash-table-iterator ((mname hash-table) &body body &environment env)
     
    26182624   any objects remain in the hash table. When the first value is non-NIL,
    26192625   the second and third values are the key and the value of the next object."
    2620   (let ((state (gensym))
    2621         (htab (gensym)))
    2622     (multiple-value-bind (body decls) (parse-body body env)
    2623       `(let* ((,htab ,hash-table)
    2624               (,state (vector nil nil nil
    2625                               nil nil)))
    2626         (declare (dynamic-extent ,state))
    2627         (unwind-protect
    2628              (macrolet ((,mname () `(do-hash-table-iteration ,',state)))
    2629                (start-hash-table-iterator ,htab ,state)
    2630                (locally ,@decls ,@body))
    2631           (finish-hash-table-iterator ,state))))))
     2626  (let* ((hash (gensym))
     2627         (keys (gensym))
     2628         (state (gensym)))
     2629    `(let* ((,hash ,hash-table)
     2630            (,keys (make-array (the fixnum (hash-table-count ,hash))))
     2631            (,state (vector ,hash 0 ,keys (enumerate-hash-keys ,hash ,keys))))
     2632      (declare (dynamic-extent ,keys ,state))
     2633      (macrolet ((,mname () `(next-hash-table-iteration ,',state)))
     2634        ,@body))))
     2635
    26322636
    26332637(eval-when (compile load eval)
     
    29902994        (setf (%process-whostate ,p) ,old-whostate)))))
    29912995
    2992 (defmacro %with-recursive-lock-ptr ((lockptr) &body body)
    2993   (let* ((locked (gensym)))
    2994     `(let ((,locked (make-lock-acquisition)))
    2995       (declare (dynamic-extent ,locked))
    2996       (unwind-protect
    2997            (progn
    2998              (%lock-recursive-lock ,lockptr ,locked )
    2999              ,@body)
    3000         (when (lock-acquisition.status ,locked) (%unlock-recursive-lock ,lockptr))))))
    3001 
    3002 (defmacro %with-recursive-lock-ptr-maybe ((lockptr) &body body)
    3003   `(when (%try-recursive-lock ,lockptr)
    3004     (unwind-protect
    3005          (progn ,@body)
    3006       (%unlock-recursive-lock ,lockptr))))
    3007 
    3008 
    3009 (defmacro with-recursive-lock ((lock) &body body)
    3010   (let* ((p (gensym)))
    3011     `(let* ((,p (recursive-lock-ptr ,lock)))
    3012       (%with-recursive-lock-ptr (,p) ,@body))))
    3013 
    3014 (defmacro with-recursive-lock-maybe ((lock) &body body)
    3015   (let* ((p (gensym)))
    3016     `(let* ((,p (recursive-lock-ptr ,lock)))
    3017       (%with-recursive-lock-ptr-maybe (,p) ,@body))))
     2996
     2997
     2998
    30182999
    30193000(defmacro with-read-lock ((lock) &body body)
     
    30363017    `(with-lock-context
    30373018      (let* ((,p ,lock))
    3038         (unwind-protect
    3039              (progn
    3040                (write-lock-rwlock ,p)
    3041                ,@body)
    3042           (unlock-rwlock ,p))))))
     3019      (unwind-protect
     3020           (progn
     3021             (write-lock-rwlock ,p)
     3022             ,@body)
     3023        (unlock-rwlock ,p))))))
    30433024
    30443025
Note: See TracChangeset for help on using the changeset viewer.