Changeset 4897


Ignore:
Timestamp:
Jul 23, 2006, 1:53:16 AM (18 years ago)
Author:
Gary Byers
Message:

Move stream-ioblock access/locking macros here.

Likewise WITH-EAGAIN.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/lib/macros.lisp

    r4112 r4897  
    31603160(declare-arch-specific-macro area-succ)
    31613161
     3162(defmacro with-ioblock-lock-grabbed ((lock)
     3163                                       &body body)
     3164  `(with-lock-grabbed (,lock)
     3165    ,@body))
     3166
     3167(defmacro with-ioblock-lock-grabbed-maybe ((lock)
     3168                                           &body body)
     3169  `(with-lock-grabbed-maybe (,lock)
     3170    ,@body))
     3171
     3172
    31623173(defmacro do-gc-areas ((area) &body body)
    31633174  (let ((initial-area (gensym)))
     
    31703181           (return))
    31713182         ,@body))))
    3172    
     3183
     3184(defmacro with-stream-ioblock-input ((ioblock stream &key
     3185                                             speedy)
     3186                                  &body body)
     3187  `(let ((,ioblock (stream-ioblock ,stream t)))
     3188     ,@(when speedy `((declare (optimize (speed 3) (safety 0)))))
     3189     (with-ioblock-input-locked (,ioblock) ,@body)))
     3190
     3191(defmacro with-stream-ioblock-output ((ioblock stream &key
     3192                                             speedy)
     3193                                  &body body)
     3194  `(let ((,ioblock (stream-ioblock ,stream t)))
     3195     ,@(when speedy `((declare (optimize (speed 3) (safety 0)))))
     3196     (with-ioblock-output-locked (,ioblock) ,@body)))
     3197
     3198(defmacro with-stream-ioblock-output-maybe ((ioblock stream &key
     3199                                                     speedy)
     3200                                            &body body)
     3201  `(let ((,ioblock (stream-ioblock ,stream t)))
     3202    ,@(when speedy `((declare (optimize (speed 3) (safety 0)))))
     3203    (with-ioblock-output-locked-maybe (,ioblock) ,@body)))
     3204
     3205(defmacro with-ioblock-input-locked ((ioblock) &body body)
     3206  (let* ((lock (gensym)))
     3207    `(let* ((,lock (locally (declare (optimize (speed 3) (safety 0)))
     3208                                  (ioblock-inbuf-lock ,ioblock))))
     3209      (if ,lock
     3210        (with-ioblock-lock-grabbed ((locally (declare (optimize (speed 3) (safety 0)))
     3211                                  (ioblock-inbuf-lock ,ioblock)))
     3212          ,@body)
     3213        (progn
     3214          (check-ioblock-owner ,ioblock)
     3215          ,@body)))))
     3216
     3217(defmacro with-ioblock-output-locked ((ioblock) &body body)
     3218  (let* ((lock (gensym)))
     3219    `(let* ((,lock (locally (declare (optimize (speed 3) (safety 0)))
     3220                                  (ioblock-inbuf-lock ,ioblock))))
     3221      (if ,lock
     3222        (with-ioblock-lock-grabbed ((locally (declare (optimize (speed 3) (safety 0)))
     3223                                  (ioblock-outbuf-lock ,ioblock)))
     3224          ,@body)
     3225        (progn
     3226          (check-ioblock-owner ,ioblock)
     3227          ,@body)))))
     3228
     3229
     3230
     3231(defmacro with-ioblock-output-locked-maybe ((ioblock) &body body)
     3232  (let* ((lock (gensym)))
     3233    `(let* ((,lock (locally (declare (optimize (speed 3) (safety 0)))
     3234                                  (ioblock-inbuf-lock ,ioblock))))
     3235      (if ,lock
     3236        (with-ioblock-lock-grabbed-maybe ((locally (declare (optimize (speed 3) (safety 0)))
     3237                                            (ioblock-outbuf-lock ,ioblock)))
     3238          ,@body)
     3239        (progn
     3240          (check-ioblock-owner ,ioblock)
     3241          ,@body)))))
     3242
     3243;;; Use this when it's possible that the fd might be in
     3244;;; a non-blocking state.  Body must return a negative of
     3245;;; the os error number on failure.
     3246;;; The use of READ-FROM-STRING below is certainly ugly, but macros
     3247;;; that expand into reader-macros don't generally trigger the reader-macro's
     3248;;; side-effects.  (Besides, the reader-macro might return a different
     3249;;; value when the macro function is expanded than it did when the macro
     3250;;; function was defined; this can happen during cross-compilation.)
     3251(defmacro with-eagain (fd direction &body body)
     3252  (let* ((res (gensym))
     3253         (eagain (symbol-value (read-from-string "#$EAGAIN"))))
     3254   `(loop
     3255      (let ((,res (progn ,@body)))
     3256        (if (eql ,res (- ,eagain))
     3257          (,(ecase direction
     3258             (:input 'process-input-wait)
     3259             (:output 'process-output-wait))
     3260           ,fd)
     3261          (return ,res))))))
     3262
    31733263(defsetf interrupt-level set-interrupt-level)
    31743264
Note: See TracChangeset for help on using the changeset viewer.