Changeset 4895


Ignore:
Timestamp:
Jul 23, 2006, 12:12:42 AM (18 years ago)
Author:
Gary Byers
Message:

Fix a few botches.

:private arg to stream creation primitives replaced with :sharing, which can
have values:

:private (the default; stream can only be accessed by the creating thread)
:lock (the old, often slow, default); most accesses to stream involve locking
:nil or :external (stream code doesn't enforce exclusion).

Location:
trunk/ccl/level-1
Files:
4 edited

Legend:

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

    r4890 r4895  
    8383(def-ccl-pointers fd-streams ()
    8484  (setq *stdin* (make-fd-stream 0
    85                                 :private nil
     85                                :sharing :lock
    8686                                :direction :input
    8787                                :interactive (not *batch-flag*)))
    88   (setq *stdout* (make-fd-stream 1 :direction :output :private nil))
    89 
    90   (setq *stderr* (make-fd-stream 2 :direction :output :private nil))
     88  (setq *stdout* (make-fd-stream 1 :direction :output :sharing :lock))
     89
     90  (setq *stderr* (make-fd-stream 2 :direction :output :sharing :lock))
    9191  (if *batch-flag*
    9292    (let* ((tty-fd (let* ((fd (fd-open "/dev/tty" #$O_RDWR)))
     
    9898                                          :direction :input
    9999                                          :interactive t
    100                                           :private nil)
    101          *terminal-output* (make-fd-stream tty-fd :direction :output :private nil)
     100                                          :sharing :lock)
     101         *terminal-output* (make-fd-stream tty-fd :direction :output :sharing :lock)
    102102         *terminal-io* (make-echoing-two-way-stream
    103103                        *terminal-input* *terminal-output*))
  • trunk/ccl/level-1/l1-sockets.lisp

    r4890 r4895  
    569569                    keepalive reuse-address nodelay broadcast linger
    570570                    local-port local-host backlog class out-of-band-inline
    571                     local-filename remote-filename private)
     571                    local-filename remote-filename sharing)
    572572  "Create and return a new socket."
    573573  (declare (dynamic-extent keys))
     
    575575                   keepalive reuse-address nodelay broadcast linger
    576576                   local-port local-host backlog class out-of-band-inline
    577                    local-filename remote-filename private))
     577                   local-filename remote-filename sharing))
    578578  (ecase address-family
    579579    ((:file) (apply #'make-file-socket keys))
     
    666666
    667667
    668 (defun make-tcp-stream (fd &key format eol (class 'tcp-stream) private &allow-other-keys)
     668(defun make-tcp-stream (fd &key format eol (class 'tcp-stream) sharing &allow-other-keys)
    669669  (declare (ignore eol))                ;???
    670670  (let ((element-type (ecase format
     
    677677                    :direction :io
    678678                    :element-type element-type
    679                     :private private)))
    680 
    681 (defun make-file-socket-stream (fd &key format eol (class 'file-socket-stream)  private &allow-other-keys)
     679                    :sharing sharing)))
     680
     681(defun make-file-socket-stream (fd &key format eol (class 'file-socket-stream)  sharing &allow-other-keys)
    682682  (declare (ignore eol))                ;???
    683683  (let ((element-type (ecase format
     
    690690                    :direction :io
    691691                    :element-type element-type
    692                     :private private)))
     692                    :sharing sharing)))
    693693
    694694(defun make-tcp-listener-socket (fd &rest keys &key backlog &allow-other-keys)
  • trunk/ccl/level-1/l1-streams.lisp

    r4893 r4895  
    275275(defmethod close ((stream stream) &key abort)
    276276  (declare (ignore abort))
    277   (with-slots ((closed closed)) stream
    278     (unless closed
    279       (setf closed t))))
     277  (open-stream-p stream))
    280278
    281279
     
    420418
    421419(defmacro with-ioblock-input-locked ((ioblock) &body body)
    422   `(if (check-ioblock-owner ,ioblock)
    423     (progn ,@body)
    424     (with-ioblock-lock-grabbed ((locally (declare (optimize (speed 3) (safety 0)))
     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)))
    425425                                  (ioblock-inbuf-lock ,ioblock)))
    426       ,@body)))
     426          ,@body)
     427        (progn
     428          (check-ioblock-owner ,ioblock)
     429          ,@body)))))
     430
    427431
    428432(defmacro with-ioblock-output-locked ((ioblock) &body body)
    429   `(if (check-ioblock-owner ,ioblock)
    430     (progn ,@body)
    431     (with-ioblock-lock-grabbed ((locally (declare (optimize (speed 3) (safety 0)))
     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)))
    432438                                  (ioblock-outbuf-lock ,ioblock)))
    433       ,@body)))
     439          ,@body)
     440        (progn
     441          (check-ioblock-owner ,ioblock)
     442          ,@body)))))
    434443
    435444(defmacro with-ioblock-output-locked-maybe ((ioblock) &body body)
    436   `(if (check-ioblock-owner ,ioblock)
    437     (progn ,@body)
    438     (with-ioblock-lock-grabbed-maybe ((locally (declare (optimize (speed 3) (safety 0)))
    439                                         (ioblock-outbuf-lock ,ioblock)))
    440       ,@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)))))
    441455
    442456(defun %ioblock-advance (ioblock read-p)
     
    484498      (setf (io-buffer-idx buf) (the fixnum (1+ idx)))
    485499      (schar (io-buffer-buffer buf) idx))))
     500
     501(declaim (inline %private-ioblock-tyi))
     502(defun %private-ioblock-tyi (ioblock)
     503  (declare (optimize (speed 3) (safety 0)))
     504  (check-ioblock-owner ioblock)
     505  (if (ioblock-untyi-char ioblock)
     506    (prog1 (ioblock-untyi-char ioblock)
     507      (setf (ioblock-untyi-char ioblock) nil))
     508    (let* ((buf (ioblock-inbuf ioblock))
     509           (idx (io-buffer-idx buf))
     510           (limit (io-buffer-count buf)))
     511      (declare (fixnum idx limit))
     512      (when (= idx limit)
     513        (unless (%ioblock-advance ioblock t)
     514          (return-from %private-ioblock-tyi (if (ioblock-eof ioblock) :eof)))
     515        (setq idx (io-buffer-idx buf)
     516              limit (io-buffer-count buf)))
     517      (setf (io-buffer-idx buf) (the fixnum (1+ idx)))
     518      (schar (io-buffer-buffer buf) idx))))
     519
     520(declaim (inline %locked-ioblock-tyi))
     521(defun %locked-ioblock-tyi (ioblock)
     522  (declare (optimize (speed 3) (safety 0)))
     523  (with-ioblock-lock-grabbed ((locally (declare (optimize (speed 3) (safety 0)))
     524                                (ioblock-inbuf-lock ioblock)))
     525    (if (ioblock-untyi-char ioblock)
     526      (prog1 (ioblock-untyi-char ioblock)
     527        (setf (ioblock-untyi-char ioblock) nil))
     528      (let* ((buf (ioblock-inbuf ioblock))
     529             (idx (io-buffer-idx buf))
     530             (limit (io-buffer-count buf)))
     531        (declare (fixnum idx limit))
     532        (when (= idx limit)
     533          (unless (%ioblock-advance ioblock t)
     534            (return-from %locked-ioblock-tyi (if (ioblock-eof ioblock) :eof)))
     535          (setq idx (io-buffer-idx buf)
     536                limit (io-buffer-count buf)))
     537        (setf (io-buffer-idx buf) (the fixnum (1+ idx)))
     538        (schar (io-buffer-buffer buf) idx)))))
    486539
    487540(declaim (inline %ioblock-tyy-no-hang))
     
    926979                            element-shift
    927980                            interactive
    928                             private
     981                            (sharing :private)
     982                            character-p
    929983                            &allow-other-keys)
    930984  (declare (ignorable element-shift))
     985  (when sharing
     986    (unless (or (eq sharing :private)
     987                (eq sharing :lock))
     988      (if (eq sharing :external)
     989        (setq sharing nil)
     990        (report-bad-arg sharing '(member nil :private :lock :external)))))
    931991  (let* ((ioblock (or (let* ((ioblock (stream-ioblock stream nil)))
    932992                        (when ioblock
     
    934994                          ioblock))
    935995                      (stream-create-ioblock stream))))
    936     (when private
     996    (when (eq sharing :private)
    937997      (setf (ioblock-owner ioblock) *current-process*))
    938998    (when insize
     
    9451005                                :size in-size-in-octets
    9461006                                :limit insize))
    947           (unless private
     1007          (when (eq sharing :lock)
    9481008            (setf (ioblock-inbuf-lock ioblock) (make-lock)))
     1009          (if character-p
     1010            (setf (ioblock-read-char-function ioblock)
     1011                   (case sharing
     1012                     (:private '%private-ioblock-tyi)
     1013                     (:lock '%locked-ioblock-tyi)
     1014                     (t '%ioblock-tyi))))
    9491015          (setf (ioblock-element-shift ioblock) (max 0 (ceiling (log  (/ in-size-in-octets insize) 2))))
    9501016          )))
     
    9671033                                  :limit outsize
    9681034                                  :size out-size-in-octets))
    969             (unless private
     1035            (when (eq sharing :lock)
    9701036              (setf (ioblock-outbuf-lock ioblock) (make-lock)))
    9711037            (setf (ioblock-element-shift ioblock) (max 0 (ceiling (log (/ out-size-in-octets outsize) 2))))
     
    10251091                          (element-type 'character)
    10261092                          (class 'fd-stream)
    1027                           (private t))
     1093                          (sharing :private))
    10281094  (let* ((in-p (member direction '(:io :input)))
    10291095         (out-p (member direction '(:io :output)))
     
    10441110                                                  (select-stream-force-output-function class))
    10451111                         :close-function 'fd-stream-close
    1046                          :private private)))
     1112                         :sharing sharing
     1113                         :character-p char-p)))
    10471114 
    10481115;;;  Fundamental streams.
     
    11331200                                           fundamental-binary-stream
    11341201                                           binary-input-stream)
     1202    ())
     1203
     1204(defclass binary-output-stream (output-stream binary-stream)
    11351205    ())
    11361206
     
    16331703  (when (slot-value s 'string)
    16341704    (setf (slot-value s 'string) nil)
    1635     (call-next-method)
    16361705    t))
    16371706
     
    25432612                      (class *default-file-stream-class*)
    25442613                      (elements-per-buffer *elements-per-buffer*)
    2545                       (private t))
     2614                      (sharing :private))
    25462615  "Return a stream which reads from or writes to FILENAME.
    25472616  Defined keywords:
     
    25632632                          class
    25642633                          external-format
    2565                           private))
     2634                          sharing))
    25662635      (retry-open ()
    25672636                  :report (lambda (stream) (format stream "Retry opening ~s" filename))
  • trunk/ccl/level-1/l1-sysio.lisp

    r4890 r4895  
    509509                         class
    510510                         external-format
    511                          private)
     511                         sharing)
    512512
    513513  (let* ((temp-name nil)
     
    570570                              :element-type element-type
    571571                              :elements-per-buffer elements-per-buffer
    572                               :private private)
     572                              :sharing sharing)
    573573              (let* ((in-p (member direction '(:io :input)))
    574574                     (out-p (member direction '(:io :output)))
     
    614614                               :device fd
    615615                               :external-format real-external-format
    616                                :private private))
     616                               :sharing sharing))
    617617                     (ioblock (stream-ioblock fstream)))
    618618                (setf (stream-filename fstream) (namestring pathname)
Note: See TracChangeset for help on using the changeset viewer.