gnu: r-biocviews: Update to 1.64.1.
[jackhill/guix/guix.git] / gnu / packages / patches / guile-fibers-epoll-instance-is-dead.patch
1 From 5db4077e9f5166033637d2af9532ec6144b85646 Mon Sep 17 00:00:00 2001
2 From: Maxime Devos <maximedevos@telenet.be>
3 Date: Thu, 30 Jun 2022 14:21:47 +0000
4 Subject: [PATCH 1/2] Fix behaviour of 'epoll-wake!' after 'run-fibers'.
5
6 This avoids the "epoll instance is dead" error noticed in
7 GNUnet-Scheme's test suite, as reported at
8 <https://github.com/wingo/fibers/issues/61>.
9 A test is added in the next commit.
10
11 This patch has been applied upstream, but there hasn't been
12 a new release yet at time of writing.
13
14 * fibers/epoll.scm (epoll-wake!)[dead]: Instead of throwing an error,
15 just return #t.
16 ---
17 fibers/epoll.scm | 8 +++++++-
18 1 file changed, 7 insertions(+), 1 deletion(-)
19
20 diff --git a/fibers/epoll.scm b/fibers/epoll.scm
21 index d26db4d..eb63242 100644
22 --- a/fibers/epoll.scm
23 +++ b/fibers/epoll.scm
24 @@ -1,6 +1,7 @@
25 ;; epoll
26
27 ;;;; Copyright (C) 2016 Andy Wingo <wingo@pobox.com>
28 +;;;; Copyright (C) 2022 Maxime Devos <maximedevos@telenet.be>
29 ;;;;
30 ;;;; This library is free software; you can redistribute it and/or
31 ;;;; modify it under the terms of the GNU Lesser General Public
32 @@ -135,7 +136,12 @@ epoll wait (if appropriate)."
33 ('waiting
34 (primitive-epoll-wake (fileno (epoll-wake-write-pipe epoll))))
35 ('not-waiting #t)
36 - ('dead (error "epoll instance is dead"))))
37 + ;; This can happen if a fiber was waiting on a condition and
38 + ;; run-fibers completes before the fiber completes and afterwards
39 + ;; the condition is signalled. In that case, we don't have to
40 + ;; resurrect the fiber or something, we can just do nothing.
41 + ;; (Bug report: https://github.com/wingo/fibers/issues/61)
42 + ('dead #t)))
43
44 (define (epoll-default-folder fd events seed)
45 (acons fd events seed))
46
47 From c01d3853eb56ea4adacc31f51f6e917f8c0abe1c Mon Sep 17 00:00:00 2001
48 From: Maxime Devos <maximedevos@telenet.be>
49 Date: Thu, 30 Jun 2022 14:18:36 +0000
50 Subject: [PATCH 2/2] Test for issue #61.
51
52 * tests/conditions.scm: Add a test.
53 ---
54 tests/conditions.scm | 20 ++++++++++++++++++++
55 1 file changed, 20 insertions(+)
56
57 diff --git a/tests/conditions.scm b/tests/conditions.scm
58 index 505c42a..179605a 100644
59 --- a/tests/conditions.scm
60 +++ b/tests/conditions.scm
61 @@ -1,6 +1,7 @@
62 ;; Fibers: cooperative, event-driven user-space threads.
63
64 ;;;; Copyright (C) 2016 Free Software Foundation, Inc.
65 +;;;; Copyright (C) 2022 Maxime Devos <maximedevos@telenet.be>
66 ;;;;
67 ;;;; This library is free software; you can redistribute it and/or
68 ;;;; modify it under the terms of the GNU Lesser General Public
69 @@ -21,6 +22,7 @@
70 #:use-module (fibers)
71 #:use-module (fibers conditions)
72 #:use-module (fibers operations)
73 + #:use-module (fibers scheduler)
74 #:use-module (fibers timers))
75
76 (define failed? #f)
77 @@ -78,4 +80,22 @@
78 (wait cv)
79 #t))
80
81 +;; Make a condition, wait for it inside a fiber, let the fiber abruptly
82 +;; terminate and signal the condition afterwards. This tests for the bug
83 +;; noticed at <https://github.com/wingo/fibers/issues/61>.
84 +(assert-equal #t
85 + (let ((cv (make-condition)))
86 + (run-fibers
87 + (lambda ()
88 + (spawn-fiber (lambda () (wait cv)))
89 + (yield-current-task)) ; let the other fiber wait forever
90 + ;; This test relies on not draining -- this is the default,
91 + ;; but let's make this explicit.
92 + #:drain? #false ;
93 + ;; For simplicity, disable concurrency and preemption.
94 + ;; That way, we can use 'yield-current-task' instead of an
95 + ;; arbitrary sleep time.
96 + #:hz 0 #:parallelism 1)
97 + (signal-condition! cv)))
98 +
99 (exit (if failed? 1 0))