Changeset 4901
- Timestamp:
- Jul 23, 2006, 2:03:32 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/ccl/level-1/l1-streams.lisp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ccl/level-1/l1-streams.lisp
r4895 r4901 374 374 (report-bad-arg (ioblock-stream ioblock) '(and binary-stream output-stream))) 375 375 376 (defun ioblock-no-char acter-input (ioblock)376 (defun ioblock-no-charr-input (ioblock) 377 377 (report-bad-arg (ioblock-stream ioblock) '(and character-stream input-stream))) 378 378 379 (defun ioblock-no-char acter-output (ioblock)379 (defun ioblock-no-char-output (ioblock) 380 380 (report-bad-arg (ioblock-stream ioblock) '(and character-stream output-stream))) 381 381 … … 397 397 398 398 399 (defmacro with-ioblock-lock-grabbed ((lock)400 &body body)401 `(with-lock-grabbed (,lock)402 ,@body))403 404 (defmacro with-ioblock-lock-grabbed-maybe ((lock)405 &body body)406 `(with-lock-grabbed-maybe (,lock)407 ,@body))408 409 399 ;;; ioblock must really be an ioblock or you will crash 410 400 ;;; Also: the expression "ioblock" is evaluated multiple times. … … 417 407 (error "Stream ~s is private to ~s" (ioblock-stream ioblock) owner))))) 418 408 419 (defmacro with-ioblock-input-locked ((ioblock) &body body) 420 (let* ((lock (gensym))) 421 `(let* ((,lock (locally (declare (optimize (speed 3) (safety 0))) 422 (ioblock-inbuf-lock ,ioblock)))) 423 (if ,lock 424 (with-ioblock-lock-grabbed ((locally (declare (optimize (speed 3) (safety 0))) 425 (ioblock-inbuf-lock ,ioblock))) 426 ,@body) 427 (progn 428 (check-ioblock-owner ,ioblock) 429 ,@body))))) 430 431 432 (defmacro with-ioblock-output-locked ((ioblock) &body body) 433 (let* ((lock (gensym))) 434 `(let* ((,lock (locally (declare (optimize (speed 3) (safety 0))) 435 (ioblock-inbuf-lock ,ioblock)))) 436 (if ,lock 437 (with-ioblock-lock-grabbed ((locally (declare (optimize (speed 3) (safety 0))) 438 (ioblock-outbuf-lock ,ioblock))) 439 ,@body) 440 (progn 441 (check-ioblock-owner ,ioblock) 442 ,@body))))) 443 444 (defmacro with-ioblock-output-locked-maybe ((ioblock) &body body) 445 (let* ((lock (gensym))) 446 `(let* ((,lock (locally (declare (optimize (speed 3) (safety 0))) 447 (ioblock-inbuf-lock ,ioblock)))) 448 (if ,lock 449 (with-ioblock-lock-grabbed-maybe ((locally (declare (optimize (speed 3) (safety 0))) 450 (ioblock-outbuf-lock ,ioblock))) 451 ,@body) 452 (progn 453 (check-ioblock-owner ,ioblock) 454 ,@body))))) 409 410 411 412 455 413 456 414 (defun %ioblock-advance (ioblock read-p) … … 459 417 ioblock 460 418 read-p)) 419 461 420 (declaim (inline %ioblock-read-byte)) 462 421 463 ;;; Should only be called with the ioblock locked 422 ;;; Should only be called with the ioblock locked, if that's necessary. 423 ;;; The whole "bivalent streams" nonsense makes this more complicated 424 ;;; than it should be. (Yes, I understand the rationale for that, 425 ;;; but discovering what type of array we have on each call isn't 426 ;;; a good approach to the problem.) That's actually not entirely 427 ;;; the fault of bivalent streams, to be honest. 464 428 (defun %ioblock-read-byte (ioblock) 465 429 (declare (optimize (speed 3) (safety 0))) … … 477 441 limit (io-buffer-count buf))) 478 442 (setf (io-buffer-idx buf) (the fixnum (1+ idx))) 479 (aref (the (simple-array (unsigned-byte 8) (*)) 480 (io-buffer-buffer buf)) idx)))) 443 (let* ((vec (io-buffer-buffer buf))) 444 (if (typep vec 'simple-string) 445 (aref (the (simple-array (unsigned-byte 8) (*)) 446 vec) idx) 447 (uvref vec idx)))))) 448 449 (declaim (inline %private-ioblock-read-byte)) 450 (defun %private-ioblock-read-byte (ioblock) 451 (declare (optimize (speed 3) (safety 0))) 452 (check-ioblock-owner ioblock) 453 (if (ioblock-untyi-char ioblock) 454 (prog1 (%char-code (ioblock-untyi-char ioblock)) 455 (setf (ioblock-untyi-char ioblock) nil)) 456 (let* ((buf (ioblock-inbuf ioblock)) 457 (idx (io-buffer-idx buf)) 458 (limit (io-buffer-count buf))) 459 (declare (fixnum idx limit)) 460 (when (= idx limit) 461 (unless (%ioblock-advance ioblock t) 462 (return-from %private-ioblock-read-byte :eof)) 463 (setq idx (io-buffer-idx buf) 464 limit (io-buffer-count buf))) 465 (setf (io-buffer-idx buf) (the fixnum (1+ idx))) 466 (let* ((vec (io-buffer-buffer buf))) 467 (if (typep vec 'simple-string) 468 (aref (the (simple-array (unsigned-byte 8) (*)) 469 vec) idx) 470 (uvref vec idx)))))) 471 472 (defun %locked-ioblock-read-byte (ioblock) 473 (declare (optimize (speed 3) (safety 0))) 474 (with-ioblock-lock-grabbed ((locally (declare (optimize (speed 3) (safety 0))) 475 (ioblock-inbuf-lock ioblock))) 476 (if (ioblock-untyi-char ioblock) 477 (prog1 (%char-code (ioblock-untyi-char ioblock)) 478 (setf (ioblock-untyi-char ioblock) nil)) 479 (let* ((buf (ioblock-inbuf ioblock)) 480 (idx (io-buffer-idx buf)) 481 (limit (io-buffer-count buf))) 482 (declare (fixnum idx limit)) 483 (when (= idx limit) 484 (unless (%ioblock-advance ioblock t) 485 (return-from %locked-ioblock-read-byte :eof)) 486 (setq idx (io-buffer-idx buf) 487 limit (io-buffer-count buf))) 488 (setf (io-buffer-idx buf) (the fixnum (1+ idx))) 489 (let* ((vec (io-buffer-buffer buf))) 490 (if (typep vec 'simple-string) 491 (aref (the (simple-array (unsigned-byte 8) (*)) 492 vec) idx) 493 (uvref vec idx))))))) 494 495 481 496 482 497 (declaim (inline %ioblock-tyi)) … … 1922 1937 (with-slots (ioblock) s 1923 1938 (not (null ioblock)))) 1924 1925 (defun stream-ioblock (stream &optional (error-if-nil t)) 1939 1940 (declaim (inline stream-ioblock)) 1941 1942 (defun stream-ioblock (stream error-if-nil) 1926 1943 (with-slots (ioblock) stream 1927 1944 (or ioblock … … 2043 2060 2044 2061 2045 (defmacro with-stream-ioblock-input ((ioblock stream &key2046 speedy)2047 &body body)2048 `(let ((,ioblock (stream-ioblock ,stream)))2049 ,@(when speedy `((declare (optimize (speed 3) (safety 0)))))2050 (with-ioblock-input-locked (,ioblock) ,@body)))2051 2052 (defmacro with-stream-ioblock-output ((ioblock stream &key2053 speedy)2054 &body body)2055 `(let ((,ioblock (stream-ioblock ,stream)))2056 ,@(when speedy `((declare (optimize (speed 3) (safety 0)))))2057 (with-ioblock-output-locked (,ioblock) ,@body)))2058 2059 (defmacro with-stream-ioblock-output-maybe ((ioblock stream &key2060 speedy)2061 &body body)2062 `(let ((,ioblock (stream-ioblock ,stream)))2063 ,@(when speedy `((declare (optimize (speed 3) (safety 0)))))2064 (with-ioblock-output-locked-maybe (,ioblock) ,@body)))2065 2062 2066 2063 (defmethod stream-read-char ((stream buffered-character-input-stream-mixin)) 2067 ( with-stream-ioblock-input (ioblock stream :speedy t)2068 ( %ioblock-tyiioblock)))2064 (let* ((ioblock (stream-ioblock stream t))) 2065 (funcall (ioblock-read-char-function ioblock) ioblock))) 2069 2066 2070 2067 (defmethod stream-read-char-no-hang ((stream buffered-character-input-stream-mixin)) … … 2323 2320 2324 2321 2325 ;;; Use this when it's possible that the fd might be in 2326 ;;; a non-blocking state. Body must return a negative of 2327 ;;; the os error number on failure. 2328 ;;; The use of READ-FROM-STRING below is certainly ugly, but macros 2329 ;;; that expand into reader-macros don't generally trigger the reader-macro's 2330 ;;; side-effects. (Besides, the reader-macro might return a different 2331 ;;; value when the macro function is expanded than it did when the macro 2332 ;;; function was defined; this can happen during cross-compilation.) 2333 (defmacro with-eagain (fd direction &body body) 2334 (let* ((res (gensym)) 2335 (eagain (symbol-value (read-from-string "#$EAGAIN")))) 2336 `(loop 2337 (let ((,res (progn ,@body))) 2338 (if (eql ,res (- ,eagain)) 2339 (,(ecase direction 2340 (:input 'process-input-wait) 2341 (:output 'process-output-wait)) 2342 ,fd) 2343 (return ,res)))))) 2322 2344 2323 2345 2324
Note:
See TracChangeset
for help on using the changeset viewer.
