Changeset 14750


Ignore:
Timestamp:
Apr 28, 2011, 6:05:40 PM (14 years ago)
Author:
Shannon Spires
Message:

#'background-process-run-function now contains a destructuring-bind so
you can call it [more] symmetrically to #'process-run-function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/cocoa-ide/cocoa-listener.lisp

    r14699 r14750  
    893893    ())
    894894
    895 (defun background-process-run-function (name function)
    896   (let* ((process (make-process name :class 'background-cocoa-listener-process))
    897          (info (make-deferred-cocoa-listener-stream-info :process process))
    898          (input-stream (make-instance 'deferred-cocoa-listener-input-stream
    899                                       :info info))
    900          (output-stream (make-instance 'deferred-cocoa-listener-output-stream
    901                                        :info info)))
    902     (setf (slot-value process 'input-stream) input-stream
    903           (slot-value process 'output-stream) output-stream)
    904     (process-preset process
    905                     (lambda ()
    906                       (let* ((*terminal-io* (make-two-way-stream input-stream output-stream)))
    907                         (ccl::add-auto-flush-stream output-stream)
    908                         (unwind-protect
    909                              (funcall function)
    910                           (remove-auto-flush-stream output-stream)
    911                           (let* ((w (slot-value process 'window)))
    912                             (when w
    913                               (let* ((doc (#/document w)))
    914                                 (unless (%null-ptr-p doc)
    915                                   (when (eq *current-process*
    916                                             (hemlock-document-process doc))
    917                                     (setf (hemlock-document-process doc) nil))))
    918                               (cond ((#/isVisible w)
    919                                      (format output-stream "~%~%{process ~s exiting}~%" *current-process*))
    920                                     (t
    921                                      (#/performSelectorOnMainThread:withObject:waitUntilDone:
    922                                       w
    923                                       (@selector #/close)
    924                                       +null-ptr+
    925                                       t)))
    926                               (close input-stream)
    927                               (close output-stream)))))))
    928     (process-enable process)))
     895(defun background-process-run-function (keywords function)
     896  (destructuring-bind (&key (name "Anonymous")
     897                            (priority  0)
     898                            (stack-size ccl::*default-control-stack-size*)
     899                            (vstack-size ccl::*default-value-stack-size*)
     900                            (tstack-size ccl::*default-temp-stack-size*)
     901                            (initial-bindings ())
     902                            (persistent nil)
     903                            (use-standard-initial-bindings t)
     904                            (termination-semaphore nil)
     905                            (allocation-quantum (default-allocation-quantum)))
     906                      keywords
     907    (setq priority (require-type priority 'fixnum))
     908    (let* ((process (make-process name
     909                                  :class 'background-cocoa-listener-process
     910                                  :priority priority
     911                                  :stack-size stack-size
     912                                  :vstack-size vstack-size
     913                                  :tstack-size tstack-size
     914                                  :persistent persistent
     915                                  :use-standard-initial-bindings use-standard-initial-bindings
     916                                  :initial-bindings initial-bindings
     917                                  :termination-semaphore termination-semaphore
     918                                  :allocation-quantum allocation-quantum))
     919           (info (make-deferred-cocoa-listener-stream-info :process process))
     920           (input-stream (make-instance 'deferred-cocoa-listener-input-stream
     921                           :info info))
     922           (output-stream (make-instance 'deferred-cocoa-listener-output-stream
     923                            :info info)))
     924      (setf (slot-value process 'input-stream) input-stream
     925            (slot-value process 'output-stream) output-stream)
     926      (process-preset process
     927                      (lambda ()
     928                        (let* ((*terminal-io* (make-two-way-stream input-stream output-stream)))
     929                          (ccl::add-auto-flush-stream output-stream)
     930                          (unwind-protect
     931                              (funcall function)
     932                            (remove-auto-flush-stream output-stream)
     933                            (let* ((w (slot-value process 'window)))
     934                              (when w
     935                                (let* ((doc (#/document w)))
     936                                  (unless (%null-ptr-p doc)
     937                                    (when (eq *current-process*
     938                                              (hemlock-document-process doc))
     939                                      (setf (hemlock-document-process doc) nil))))
     940                                (cond ((#/isVisible w)
     941                                       (format output-stream "~%~%{process ~s exiting}~%" *current-process*))
     942                                      (t
     943                                       (#/performSelectorOnMainThread:withObject:waitUntilDone:
     944                                        w
     945                                        (@selector #/close)
     946                                        +null-ptr+
     947                                        t)))
     948                                (close input-stream)
     949                                (close output-stream)))))))
     950      (process-enable process))))
Note: See TracChangeset for help on using the changeset viewer.