gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet-scheme] 218/324: mq-impl/stream: Name the reader and writer thun


From: gnunet
Subject: [gnunet-scheme] 218/324: mq-impl/stream: Name the reader and writer thunks.
Date: Tue, 21 Sep 2021 13:24:18 +0200

This is an automated email from the git hooks/post-receive script.

maxime-devos pushed a commit to branch master
in repository gnunet-scheme.

commit a4fa419b648276beb2565cbab0d6b795a78dd7e2
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Wed Sep 1 09:46:22 2021 +0200

    mq-impl/stream: Name the reader and writer thunks.
    
    This makes writing changelog entries simpler,
    and will be useful for unifying connect/fibers and
    port->message-queue.
    
    * gnu/gnunet/mq-impl/stream.scm
      (port->message-queue)[start-reader!,start-writer!]:
      Move arguments of 'spawn' to a named variable.
---
 gnu/gnunet/mq-impl/stream.scm | 118 +++++++++++++++++++++---------------------
 1 file changed, 60 insertions(+), 58 deletions(-)

diff --git a/gnu/gnunet/mq-impl/stream.scm b/gnu/gnunet/mq-impl/stream.scm
index 6a03b8a..a8d0606 100644
--- a/gnu/gnunet/mq-impl/stream.scm
+++ b/gnu/gnunet/mq-impl/stream.scm
@@ -281,64 +281,66 @@ XXX: Likewise for connect/fibers?"
       ;; an appropriate error, unless the other fiber will do it already.
       (define closed-condition (make-condition))
       (define mq (make-message-queue handlers error-handler interrupt!))
-      (spawn (lambda ()
-              (define-values (key . rest)
-                (let/ec escape
-                  (define wait-op
-                    (choice-operation
-                     (wait-until-port-readable-operation port)
-                     (wrap-operation (wait-operation closed-condition)
-                                     (lambda ()
-                                       (escape 'input:regular-end-fof-file)))))
-                  (define (new-waiter . _)
-                    (perform-operation wait-op))
-                  ;; XXX: if (define-values error ...) is written and
-                  ;; 'handle-input!' raises an error (resulting in a 
backtrace),
-                  ;; a segfault can
-                  ;; happen: 
<https://debbugs.gnu.org/cgi/bugreport.cgi?bug=50153>.
-                  (parameterize ((current-read-waiter new-waiter))
-                    (handle-input! mq port #:return values))))
-              (when (signal-condition! closed-condition)
-                (apply inject-error! mq key rest))))
-      (spawn (lambda ()
-              (let/ec escape
-                ;; operation for calling the escape continuation when
-                ;; when the other fiber detected the connection is broken
-                (define escape-when-closed-operation
-                  (wrap-operation (wait-operation closed-condition)
-                                  escape))
-                ;; operation for waiting until the port is writable
-                ;; or the other fiber detected the connection is broken.
-                (define wait-writable-operation
-                  (choice-operation
-                   escape-when-closed-operation
-                   (wait-until-port-writable-operation port)))
-                (define (wait!)
-                  (perform-operation
-                   (choice-operation
-                    (prepare-await-trigger! rcvar)
-                     ;; Don't wait for the port to be writable here!
-                     ;;
-                     ;; Otherwise, if the port is writable, but the message
-                     ;; queue has nothing buffered for a while, the fiber
-                     ;; keeps spinning.
-                     ;;
-                     ;; XXX it would be nice if it could be detected when the
-                     ;; write end of the port is closed.
-                    escape-when-closed-operation)))
-                (define (wait!/blocking)
-                  (perform-operation wait-writable-operation))
-                (define old-waiter (current-write-waiter))
-                (define (new-waiter p)
-                  (if (eq? p port)
-                      (wait!/blocking)
-                      ;; Maybe a backtrace is being printed,
-                      ;; 'system-async-mark' is used ...
-                      (old-waiter p)))
-                (parameterize ((current-write-waiter new-waiter))
-                  (handle-output! mq port wait!)))
-              (when (signal-condition! closed-condition)
-                (inject-error! mq 'input:regular-end-of-file))))
+      (define (start-reader!)
+       (define-values (key . rest)
+         (let/ec escape
+           (define wait-op
+             (choice-operation
+              (wait-until-port-readable-operation port)
+              (wrap-operation (wait-operation closed-condition)
+                              (lambda ()
+                                (escape 'input:regular-end-fof-file)))))
+           (define (new-waiter . _)
+             (perform-operation wait-op))
+           ;; XXX: if (define-values error ...) is written and
+           ;; 'handle-input!' raises an error (resulting in a backtrace),
+           ;; a segfault can
+           ;; happen: <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=50153>.
+           (parameterize ((current-read-waiter new-waiter))
+             (handle-input! mq port #:return values))))
+       (when (signal-condition! closed-condition)
+         (apply inject-error! mq key rest)))
+      (define (start-writer!)
+       (let/ec escape
+         ;; operation for calling the escape continuation when
+         ;; when the other fiber detected the connection is broken
+         (define escape-when-closed-operation
+           (wrap-operation (wait-operation closed-condition)
+                           escape))
+         ;; operation for waiting until the port is writable
+         ;; or the other fiber detected the connection is broken.
+         (define wait-writable-operation
+           (choice-operation
+            escape-when-closed-operation
+            (wait-until-port-writable-operation port)))
+         (define (wait!)
+           (perform-operation
+            (choice-operation
+             (prepare-await-trigger! rcvar)
+              ;; Don't wait for the port to be writable here!
+              ;;
+              ;; Otherwise, if the port is writable, but the message
+              ;; queue has nothing buffered for a while, the fiber
+              ;; keeps spinning.
+              ;;
+              ;; XXX it would be nice if it could be detected when the
+              ;; write end of the port is closed.
+             escape-when-closed-operation)))
+         (define (wait!/blocking)
+           (perform-operation wait-writable-operation))
+         (define old-waiter (current-write-waiter))
+         (define (new-waiter p)
+           (if (eq? p port)
+               (wait!/blocking)
+               ;; Maybe a backtrace is being printed,
+               ;; 'system-async-mark' is used ...
+               (old-waiter p)))
+         (parameterize ((current-write-waiter new-waiter))
+           (handle-output! mq port wait!)))
+       (when (signal-condition! closed-condition)
+         (inject-error! mq 'input:regular-end-of-file)))
+      (spawn start-reader!)
+      (spawn start-writer!)
       mq)
 
     (define* (connect/fibers config service-name handlers error-handler

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]