compile: Fix race condition on completion progress.

This prevent a race condition where multiple compilation threads could report
the same progress.

* guix/build/compile.scm (compile-files)<completed>: Rename to...
<progress>: ...this.  Increment in same mutex region as the compilation is
reported.
This commit is contained in:
Eric Bavier 2019-09-24 20:57:34 -05:00
parent d49375c722
commit 21391f8c83
No known key found for this signature in database
GPG Key ID: FD73CAC719D32566
1 changed files with 4 additions and 5 deletions

View File

@ -169,11 +169,12 @@ BUILD-DIRECTORY, using up to WORKERS parallel workers. The resulting object
files are for HOST, a GNU triplet such as \"x86_64-linux-gnu\"." files are for HOST, a GNU triplet such as \"x86_64-linux-gnu\"."
(define progress-lock (make-mutex)) (define progress-lock (make-mutex))
(define total (length files)) (define total (length files))
(define completed 0) (define progress 0)
(define (build file) (define (build file)
(with-mutex progress-lock (with-mutex progress-lock
(report-compilation file total completed)) (report-compilation file total progress)
(set! progress (+ 1 progress)))
;; Exit as soon as something goes wrong. ;; Exit as soon as something goes wrong.
(exit-on-exception (exit-on-exception
@ -185,9 +186,7 @@ files are for HOST, a GNU triplet such as \"x86_64-linux-gnu\"."
#:output-file (string-append build-directory "/" #:output-file (string-append build-directory "/"
(scm->go relative)) (scm->go relative))
#:opts (append warning-options #:opts (append warning-options
(optimization-options relative))))))) (optimization-options relative))))))))
(with-mutex progress-lock
(set! completed (+ 1 completed))))
(with-augmented-search-path %load-path source-directory (with-augmented-search-path %load-path source-directory
(with-augmented-search-path %load-compiled-path build-directory (with-augmented-search-path %load-compiled-path build-directory