diff options
author | Robin <Robin.Watts@artifex.com> | 2016-05-11 11:36:20 -0700 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-05-12 00:37:28 +0100 |
commit | fca826d452afd2c4854b75c94a41a731897f10f1 (patch) | |
tree | 4b9635bc33f8abcf3816b4f26ff2a8f45687ec05 /source | |
parent | 1a6b5b8bd03defa41c559a53d446b262be3ba8e8 (diff) | |
download | mupdf-fca826d452afd2c4854b75c94a41a731897f10f1.tar.xz |
Fix race condition in bgprint.
There was a race condition on bgprint.pagenum that could cause
the bgprint worker to close down early, leaving the main thread
waiting for notification of its closedown.
Diffstat (limited to 'source')
-rw-r--r-- | source/tools/mudraw.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c index 55c984c4..6c9735b2 100644 --- a/source/tools/mudraw.c +++ b/source/tools/mudraw.c @@ -1343,23 +1343,26 @@ static THREAD_RETURN_TYPE worker_thread(void *arg) static THREAD_RETURN_TYPE bgprint_worker(void *arg) { fz_cookie cookie = { 0 }; + int pagenum; + (void)arg; do { DEBUG_THREADS(("BGPrint waiting\n")); SEMAPHORE_WAIT(bgprint.start); - DEBUG_THREADS(("BGPrint woken for pagenum %d\n", bgprint.pagenum)); - if (bgprint.pagenum >= 0) + pagenum = bgprint.pagenum; + DEBUG_THREADS(("BGPrint woken for pagenum %d\n", pagenum)); + if (pagenum >= 0) { int start = gettime(); memset(&cookie, 0, sizeof(cookie)); - dodrawpage(bgprint.ctx, bgprint.page, bgprint.list, bgprint.pagenum, &cookie, start, bgprint.filename, 1); + dodrawpage(bgprint.ctx, bgprint.page, bgprint.list, pagenum, &cookie, start, bgprint.filename, 1); } - DEBUG_THREADS(("BGPrint completed band %d\n", bgprint.pagenum)); + DEBUG_THREADS(("BGPrint completed page %d\n", pagenum)); SEMAPHORE_TRIGGER(bgprint.stop); } - while (bgprint.pagenum >= 0); + while (pagenum >= 0); THREAD_RETURN(); } #endif |