diff --git a/rzip.h b/rzip.h index 38a7a86..2f6dd79 100644 --- a/rzip.h +++ b/rzip.h @@ -278,6 +278,7 @@ struct stream { long uthread_no; long unext_thread; long base_thread; + int total_threads; }; struct stream_info { diff --git a/stream.c b/stream.c index 363c1bd..26faf47 100644 --- a/stream.c +++ b/stream.c @@ -843,7 +843,7 @@ void *open_stream_in(int f, int n) if (unlikely(!sinfo)) return NULL; - total_threads = control.threads * 2; + total_threads = control.threads + 1; threads = calloc(sizeof(pthread_t), total_threads); if (unlikely(!threads)) return NULL; @@ -867,11 +867,14 @@ void *open_stream_in(int f, int n) return NULL; } + sinfo->s[0].total_threads = 1; + sinfo->s[1].total_threads = control.threads; + for (i = 0; i < n; i++) { uchar c; 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].unext_thread = sinfo->s[i].base_thread; @@ -1202,7 +1205,7 @@ fill_another: s->uthread_no, c_len, stream); create_pthread(&threads[s->uthread_no], NULL, ucompthread, (void *)s->uthread_no); - 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; /* Reached the end of this stream, no more data to read in, otherwise @@ -1217,7 +1220,7 @@ fill_another: goto fill_different_stream; } if (s->uthread_no != s->unext_thread && - !ucthread[s->uthread_no].busy && threads_busy < control.threads) + !ucthread[s->uthread_no].busy && threads_busy < s->total_threads) goto fill_another; out: s = ret_s; @@ -1240,7 +1243,7 @@ out: * ucompthread, we reset it regardless. */ init_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; return 0;