mirror of
https://github.com/ckolivas/lrzip.git
synced 2025-12-06 07:12:00 +01:00
We do not need to wait for the main process to be ready to receive the data from the threads before shutting them down.
Only wait for the "ready" semaphore if we've failed to decompress in parallel. This affords a small speedup on decompression.
This commit is contained in:
parent
8d110e3366
commit
6b73eb1394
27
stream.c
27
stream.c
|
|
@ -1126,24 +1126,20 @@ retry:
|
||||||
if (waited)
|
if (waited)
|
||||||
fatal("Failed to decompress in ucompthread\n");
|
fatal("Failed to decompress in ucompthread\n");
|
||||||
print_maxverbose("Unable to decompress in parallel, waiting for previous thread to complete before trying again\n");
|
print_maxverbose("Unable to decompress in parallel, waiting for previous thread to complete before trying again\n");
|
||||||
}
|
/* This "ready" tells this thread that we're ready to receive
|
||||||
|
* its data. We do not strictly need to wait for this, so it's
|
||||||
/* First ready, are up to this thread yet? */
|
* used when decompression fails due to inadequate memory to
|
||||||
if (!waited) {
|
* try again serialised. */
|
||||||
wait_sem(&uci->ready);
|
wait_sem(&uci->ready);
|
||||||
waited = 1;
|
waited = 1;
|
||||||
}
|
|
||||||
if (ret)
|
|
||||||
goto retry;
|
goto retry;
|
||||||
|
}
|
||||||
|
|
||||||
/* This complete tells the main thread that this thread has its
|
/* This "complete" tells the main thread that this thread has its
|
||||||
* decompressed data ready */
|
* decompressed data ready */
|
||||||
post_sem(&uci->complete);
|
post_sem(&uci->complete);
|
||||||
/* Second ready, the buffer has been grabbed by the main thread so this
|
|
||||||
* thread can exit */
|
|
||||||
wait_sem(&uci->ready);
|
|
||||||
|
|
||||||
print_maxverbose("Thread %ld returning %lld uncompressed bytes from stream %d\n", i, uci->u_len, uci->stream);
|
print_maxverbose("Thread %ld decompressed %lld bytes from stream %d\n", i, uci->u_len, uci->stream);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1230,21 +1226,22 @@ fill_another:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
/* This "ready" tells the decompression thread we're up to it */
|
/* "ready" tells the decompression thread we're ready for its data */
|
||||||
post_sem(&ucthread[s->unext_thread].ready);
|
post_sem(&ucthread[s->unext_thread].ready);
|
||||||
/* This "complete" is the deco thread telling us it's finished
|
/* This "complete" is the deco thread telling us it's finished
|
||||||
* decompressing data */
|
* decompressing data */
|
||||||
wait_sem(&ucthread[s->unext_thread].complete);
|
wait_sem(&ucthread[s->unext_thread].complete);
|
||||||
|
print_maxverbose("Taking decompressed data from thread %ld\n", s->unext_thread);
|
||||||
|
|
||||||
s->buf = ucthread[s->unext_thread].s_buf;
|
s->buf = ucthread[s->unext_thread].s_buf;
|
||||||
s->buflen = ucthread[s->unext_thread].u_len;
|
s->buflen = ucthread[s->unext_thread].u_len;
|
||||||
s->bufp = 0;
|
s->bufp = 0;
|
||||||
|
|
||||||
/* This "ready" tells the decompression thread we've taken the buffer so
|
|
||||||
* it can exit */
|
|
||||||
post_sem(&ucthread[s->unext_thread].ready);
|
|
||||||
join_pthread(threads[s->unext_thread], NULL);
|
join_pthread(threads[s->unext_thread], NULL);
|
||||||
post_sem(&ucthread[s->unext_thread].free);
|
post_sem(&ucthread[s->unext_thread].free);
|
||||||
|
/* As the ready semaphore may or may not have been waited on in
|
||||||
|
* ucompthread, we reset it regardless. */
|
||||||
|
init_sem(&ucthread[s->unext_thread].ready);
|
||||||
|
|
||||||
if (++s->unext_thread == s->base_thread + s->total_threads)
|
if (++s->unext_thread == s->base_thread + s->total_threads)
|
||||||
s->unext_thread = s->base_thread;
|
s->unext_thread = s->base_thread;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue