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