Skip to content

Commit 3b77c57

Browse files
committed
Make parallel update-what-you-can intercept all errors.
1 parent 902ef26 commit 3b77c57

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

misc.lisp

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -162,31 +162,41 @@
162162
(intern (string-upcase project))))
163163

164164

165-
(defun call-with-skipping (fun &key (stream *standard-output*))
166-
(handler-bind ((error (lambda (condition)
167-
(when (find-restart 'skip)
168-
(when (boundp '*current-mapped-source*)
169-
(format stream "~&* ~A~%" *current-mapped-source*)
170-
(format stream ":: from ~A~%"
171-
(find-source *current-mapped-source*)))
172-
(format stream "~&SKIPPING (~A)~%" condition)
173-
(invoke-restart 'skip)))))
174-
(funcall fun)))
175-
176-
(defun update-what-you-can (&optional file)
165+
(defvar *output-lock* (bt:make-lock "output-lock"))
166+
167+
(defun call-with-skipping (fun &key (stream *standard-output*) parallel)
168+
(flet ((invoke-skip (condition)
169+
(when (find-restart 'skip)
170+
(bt:with-lock-held (*output-lock*)
171+
(when (boundp '*current-mapped-source*)
172+
(format stream "~&* ~A~%" *current-mapped-source*)
173+
(format stream ":: from ~A~%"
174+
(find-source *current-mapped-source*)))
175+
(format stream "~&SKIPPING (~A)~%" condition))
176+
(invoke-restart 'skip))))
177+
(if (not parallel)
178+
(handler-bind ((error #'invoke-skip))
179+
(funcall fun))
180+
(lparallel:task-handler-bind ((error #'invoke-skip))
181+
(funcall fun)))))
182+
183+
(defun update-what-you-can (&optional file parallel)
177184
(flet ((action (stream)
178185
(call-with-skipping
179186
(lambda ()
180-
(pmap-sources (lambda (source)
181-
(force-output stream)
182-
(format t "~&Updating ~S from ~A~%"
183-
(project-name source)
184-
(location source))
185-
(update-source-cache source))))
186-
:stream stream)))
187+
(funcall (if parallel 'pmap-sources 'map-sources)
188+
(lambda (source)
189+
(bt:with-lock-held (*output-lock*)
190+
(force-output stream)
191+
(format t "~&Updating ~S from ~A~%"
192+
(project-name source)
193+
(location source)))
194+
(update-source-cache source))))
195+
:stream stream
196+
:parallel parallel)))
187197
(if file
188198
(with-open-file (stream file :direction :output
189-
:if-exists :rename-and-delete)
199+
:if-exists :rename-and-delete)
190200
(action (make-broadcast-stream *standard-output* stream)))
191201
(action *standard-output*))))
192202

upstream.lisp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
(defvar *current-mapped-source* nil)
123123

124124
(defun map-source (fun source)
125-
(let ((*current-mapped-source* (project-name source-file)))
125+
(let ((*current-mapped-source* (project-name source)))
126126
(with-simple-restart (skip "Skip ~A source" *current-mapped-source*)
127127
(funcall fun source))))
128128

0 commit comments

Comments
 (0)