mirror of
https://github.com/ckolivas/lrzip.git
synced 2025-12-06 07:12:00 +01:00
Limit the number of threads decompressing stream 0 to just 1 since it's always followed by stream 1 chunks, and it may lead to failure to decompress due to running out of memory by running too many threads.
This commit is contained in:
parent
50437a8447
commit
a6ab7c875b
1
rzip.h
1
rzip.h
|
|
@ -274,6 +274,7 @@ struct stream {
|
||||||
long uthread_no;
|
long uthread_no;
|
||||||
long unext_thread;
|
long unext_thread;
|
||||||
long base_thread;
|
long base_thread;
|
||||||
|
int total_threads;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct stream_info {
|
struct stream_info {
|
||||||
|
|
|
||||||
14
stream.c
14
stream.c
|
|
@ -789,7 +789,7 @@ void *open_stream_in(int f, int n)
|
||||||
if (unlikely(!sinfo))
|
if (unlikely(!sinfo))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
total_threads = control.threads * n;
|
total_threads = control.threads + 1;
|
||||||
threads = calloc(sizeof(pthread_t), total_threads);
|
threads = calloc(sizeof(pthread_t), total_threads);
|
||||||
if (unlikely(!threads))
|
if (unlikely(!threads))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -815,11 +815,14 @@ void *open_stream_in(int f, int n)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sinfo->s[0].total_threads = 1;
|
||||||
|
sinfo->s[1].total_threads = control.threads;
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
uchar c;
|
uchar c;
|
||||||
i64 v1, v2;
|
i64 v1, v2;
|
||||||
|
|
||||||
sinfo->s[i].base_thread = control.threads * i;
|
sinfo->s[i].base_thread = i;
|
||||||
sinfo->s[i].uthread_no = sinfo->s[i].base_thread;
|
sinfo->s[i].uthread_no = sinfo->s[i].base_thread;
|
||||||
sinfo->s[i].unext_thread = sinfo->s[i].base_thread;
|
sinfo->s[i].unext_thread = sinfo->s[i].base_thread;
|
||||||
|
|
||||||
|
|
@ -1104,9 +1107,10 @@ fill_another:
|
||||||
if (!last_head)
|
if (!last_head)
|
||||||
s->eos = 1;
|
s->eos = 1;
|
||||||
|
|
||||||
if (++s->uthread_no == s->base_thread + control.threads)
|
if (++s->uthread_no == s->base_thread + s->total_threads)
|
||||||
s->uthread_no = s->base_thread;
|
s->uthread_no = s->base_thread;
|
||||||
if (!trywait_sem(&ucthread[s->uthread_no].free)) {
|
if (s->uthread_no != s->unext_thread &&
|
||||||
|
!trywait_sem(&ucthread[s->uthread_no].free)) {
|
||||||
post_sem(&ucthread[s->uthread_no].free);
|
post_sem(&ucthread[s->uthread_no].free);
|
||||||
goto fill_another;
|
goto fill_another;
|
||||||
}
|
}
|
||||||
|
|
@ -1119,7 +1123,7 @@ out:
|
||||||
|
|
||||||
post_sem(&ucthread[s->unext_thread].ready);
|
post_sem(&ucthread[s->unext_thread].ready);
|
||||||
|
|
||||||
if (++s->unext_thread == s->base_thread + control.threads)
|
if (++s->unext_thread == s->base_thread + s->total_threads)
|
||||||
s->unext_thread = s->base_thread;
|
s->unext_thread = s->base_thread;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue