Changeset 4932


Ignore:
Timestamp:
Jul 29, 2006, 6:39:03 AM (18 years ago)
Author:
Gary Byers
Message:

ALLOCATE-RESOURCE, FREE-RESOURCE: use lock.
TODO: evaluate whether resources are worthwhile; used for string-output-stream
allocation and DELETE-DUPLICATES.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/level-1/l1-aprims.lisp

    r4645 r4932  
    12111211(defun allocate-resource (resource)
    12121212  (setq resource (require-type resource 'resource))
    1213   (let ((pool (resource.pool resource))
    1214         res)
    1215     (without-interrupts
    1216      (let ((data (pool.data pool)))
    1217        (when data
    1218          (setf res (car data)
    1219                (pool.data pool) (cdr (the cons data)))
    1220          (free-cons data))))
    1221     (if res
    1222       (let ((initializer (resource.initializer resource)))
    1223         (when initializer
    1224           (funcall initializer res)))
    1225       (setq res (funcall (resource.constructor resource))))
    1226     res))
     1213  (with-lock-grabbed ((resource.lock resource))
     1214    (let ((pool (resource.pool resource))
     1215          res)
     1216      (let ((data (pool.data pool)))
     1217        (when data
     1218          (setf res (car data)
     1219                (pool.data pool) (cdr (the cons data)))
     1220          (free-cons data)))
     1221      (if res
     1222        (let ((initializer (resource.initializer resource)))
     1223          (when initializer
     1224            (funcall initializer res)))
     1225        (setq res (funcall (resource.constructor resource))))
     1226      res)))
    12271227
    12281228(defun free-resource (resource instance)
    12291229  (setq resource (require-type resource 'resource))
    1230   (let ((pool (resource.pool resource))
    1231         (destructor (resource.destructor resource)))
    1232     (when destructor
    1233       (funcall destructor instance))
    1234     (without-interrupts
    1235      (setf (pool.data pool)
    1236            (cheap-cons instance (pool.data pool)))))
     1230  (with-lock-grabbed ((resource.lock resource))
     1231    (let ((pool (resource.pool resource))
     1232          (destructor (resource.destructor resource)))
     1233      (when destructor
     1234        (funcall destructor instance))
     1235      (setf (pool.data pool)
     1236            (cheap-cons instance (pool.data pool)))))
    12371237  resource)
    12381238
Note: See TracChangeset for help on using the changeset viewer.