From 2c7c4832b38dd606923a8554624749587f4dac0e Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 14 Feb 2021 20:37:03 +1100 Subject: [PATCH] Move thread pthread_t to control structure for later access. --- lrzip_private.h | 2 ++ stream.c | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lrzip_private.h b/lrzip_private.h index b625653..9a456b1 100644 --- a/lrzip_private.h +++ b/lrzip_private.h @@ -466,6 +466,8 @@ struct rzip_control { void (*next_tag)(rzip_control *, struct rzip_state *, i64, tag *); tag (*full_tag)(rzip_control *, struct rzip_state *, i64); i64 (*match_len)(rzip_control *, struct rzip_state *, i64, i64, i64, i64 *); + + pthread_t *pthreads; }; struct uncomp_thread { diff --git a/stream.c b/stream.c index 39299fe..8892206 100644 --- a/stream.c +++ b/stream.c @@ -82,7 +82,6 @@ typedef struct stream_thread_struct { static long output_thread; static pthread_mutex_t output_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t output_cond = PTHREAD_COND_INITIALIZER; -static pthread_t *threads; bool init_mutex(rzip_control *control, pthread_mutex_t *mutex) { @@ -877,6 +876,7 @@ i64 get_readseek(rzip_control *control, int fd) bool prepare_streamout_threads(rzip_control *control) { + pthread_t *threads; int i; /* As we serialise the generation of threads during the rzip @@ -887,7 +887,7 @@ bool prepare_streamout_threads(rzip_control *control) ++control->threads; if (NO_COMPRESS) control->threads = 1; - threads = calloc(sizeof(pthread_t), control->threads); + threads = control->pthreads = calloc(sizeof(pthread_t), control->threads); if (unlikely(!threads)) fatal_return(("Unable to calloc threads in prepare_streamout_threads\n"), false); @@ -918,7 +918,7 @@ bool close_streamout_threads(rzip_control *control) close_thread = 0; } dealloc(cthreads); - dealloc(threads); + dealloc(control->pthreads); return true; } @@ -1054,6 +1054,7 @@ void *open_stream_in(rzip_control *control, int f, int n, char chunk_bytes) struct uncomp_thread *ucthreads; struct stream_info *sinfo; int total_threads, i; + pthread_t *threads; i64 header_length; sinfo = calloc(sizeof(struct stream_info), 1); @@ -1066,7 +1067,7 @@ void *open_stream_in(rzip_control *control, int f, int n, char chunk_bytes) total_threads = control->threads + 2; else total_threads = control->threads + 1; - threads = calloc(sizeof(pthread_t), total_threads); + threads = control->pthreads = calloc(sizeof(pthread_t), total_threads); if (unlikely(!threads)) return NULL; @@ -1453,6 +1454,7 @@ error: static void clear_buffer(rzip_control *control, struct stream_info *sinfo, int streamno, int newbuf) { + pthread_t *threads = control->pthreads; stream_thread_struct *s; static int i = 0; @@ -1562,8 +1564,9 @@ static int fill_buffer(rzip_control *control, struct stream_info *sinfo, struct { i64 u_len, c_len, last_head, padded_len, header_length, max_len; uchar enc_head[25 + SALT_LEN], blocksalt[SALT_LEN]; - stream_thread_struct *sts; struct uncomp_thread *ucthreads = sinfo->ucthreads; + pthread_t *threads = control->pthreads; + stream_thread_struct *sts; uchar c_type, *s_buf; void *thr_return; @@ -1832,7 +1835,7 @@ int close_stream_in(rzip_control *control, void *ss) output_thread = 0; dealloc(sinfo->ucthreads); - dealloc(threads); + dealloc(control->pthreads); dealloc(sinfo->s); dealloc(sinfo);