From 8e128eaf058dfc9e70d19fa59ab21053845926b3 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 26 Jan 2018 10:20:38 -0800 Subject: [PATCH] zstdmt : refactor job members grouped by sharing properties --- doc/zstd_manual.html | 7 ++++--- lib/compress/zstdmt_compress.c | 38 +++++++++++++++++----------------- tests/zstreamtest.c | 4 ++-- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/doc/zstd_manual.html b/doc/zstd_manual.html index dc3f8be1b..b4aed91e5 100644 --- a/doc/zstd_manual.html +++ b/doc/zstd_manual.html @@ -926,7 +926,7 @@ size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* prefix, size_t


typedef enum {
-    ZSTD_e_continue=0, /* collect more data, encoder transparently decides when to output result, for optimal conditions */
+    ZSTD_e_continue=0, /* collect more data, encoder decides when to output compressed result, for optimal conditions */
     ZSTD_e_flush,      /* flush any data provided so far - frame will continue, future data can still reference previous data for better compression */
     ZSTD_e_end         /* flush any remaining data and close current frame. Any additional data starts a new frame. */
 } ZSTD_EndDirective;
@@ -945,10 +945,11 @@ size_t ZSTD_CCtx_refPrefix_advanced(ZSTD_CCtx* cctx, const void* prefix, size_t
                                                      and then immediately returns, just indicating that there is some data remaining to be flushed.
                                                      The function nonetheless guarantees forward progress : it will return only after it reads or write at least 1+ byte.
   - Exception : in multi-threading mode, if the first call requests a ZSTD_e_end directive, it is blocking : it will complete compression before giving back control to caller.
-  - @return provides the minimum amount of data remaining to be flushed from internal buffers
+  - @return provides a minimum amount of data remaining to be flushed from internal buffers
             or an error code, which can be tested using ZSTD_isError().
             if @return != 0, flush is not fully completed, there is still some data left within internal buffers.
-            This is useful to determine if a ZSTD_e_flush or ZSTD_e_end directive is completed.
+            This is useful for ZSTD_e_flush, since in this case more flushes are necessary to empty all buffers.
+            For ZSTD_e_end, @return == 0 when internal buffers are fully flushed and frame is completed.
   - after a ZSTD_e_end directive, if internal buffer is not fully flushed (@return != 0),
             only ZSTD_e_end or ZSTD_e_flush operations are allowed.
             Before starting a new compression job, or changing compression parameters,
diff --git a/lib/compress/zstdmt_compress.c b/lib/compress/zstdmt_compress.c
index 451bb5bf6..4e53367fd 100644
--- a/lib/compress/zstdmt_compress.c
+++ b/lib/compress/zstdmt_compress.c
@@ -300,28 +300,28 @@ static void ZSTDMT_releaseCCtx(ZSTDMT_CCtxPool* pool, ZSTD_CCtx* cctx)
 
 
 /* ------------------------------------------ */
-/* =====          Thread worker         ===== */
+/* =====          Worker thread         ===== */
 /* ------------------------------------------ */
 
 typedef struct {
-    buffer_t src;
-    const void* srcStart;
-    size_t   prefixSize;
-    size_t   srcSize;
-    size_t   consumed;
-    buffer_t dstBuff;
-    size_t   cSize;
-    size_t   dstFlushed;
-    unsigned firstChunk;
-    unsigned lastChunk;
-    unsigned frameChecksumNeeded;
-    ZSTD_pthread_mutex_t* mtctx_mutex;
-    ZSTD_pthread_cond_t* mtctx_cond;
-    ZSTD_CCtx_params params;
-    const ZSTD_CDict* cdict;
-    ZSTDMT_CCtxPool* cctxPool;
-    ZSTDMT_bufferPool* bufPool;
-    unsigned long long fullFrameSize;
+    size_t   consumed;       /* SHARED - init0 by mtctx, then modified by worker AND read by mtctx */
+    size_t   cSize;          /* SHARED - init0 by mtctx, then modified by worker AND read by mtctx */
+    ZSTD_pthread_mutex_t* mtctx_mutex;   /* Thread-safe - used by mtctx and (all) worker */
+    ZSTD_pthread_cond_t* mtctx_cond;     /* Thread-safe - used by mtctx and (all) worker */
+    ZSTDMT_CCtxPool* cctxPool;           /* Thread-safe - used by mtctx and (all) worker */
+    ZSTDMT_bufferPool* bufPool;          /* Thread-safe - used by mtctx and (all) worker */
+    buffer_t dstBuff;        /* set by worker (or mtctx), then read by worker, then modified by mtctx => no barrier */
+    buffer_t src;            /* set by mtctx, then modified by worker => no barrier */
+    const void* srcStart;    /* set by mtctx, then read by worker => no barrier */
+    size_t   prefixSize;     /* set by mtctx, then read by worker => no barrier */
+    size_t   srcSize;        /* set by mtctx, then read by worker => no barrier */
+    unsigned firstChunk;     /* set by mtctx, then read by worker => no barrier */
+    unsigned lastChunk;      /* set by mtctx, then read by worker => no barrier */
+    ZSTD_CCtx_params params;             /* set by mtctx, then read by worker => no barrier */
+    const ZSTD_CDict* cdict;             /* set by mtctx, then read by worker => no barrier */
+    unsigned long long fullFrameSize;    /* set by mtctx, then read by worker => no barrier */
+    size_t   dstFlushed;                 /* used only by mtctx */
+    unsigned frameChecksumNeeded;        /* used only by mtctx */
 } ZSTDMT_jobDescription;
 
 /* ZSTDMT_compressChunk() is a POOL_function type */
diff --git a/tests/zstreamtest.c b/tests/zstreamtest.c
index ef5cf65fb..16dcba73a 100644
--- a/tests/zstreamtest.c
+++ b/tests/zstreamtest.c
@@ -1220,9 +1220,9 @@ static int fuzzerTests_MT(U32 seed, U32 nbTests, unsigned startTest, double comp
 
         FUZ_rand(&coreSeed);
         if (nbTests >= testNb) {
-            DISPLAYUPDATE(2, "\r%6u/%6u (%08X)   ", testNb, nbTests, coreSeed);
+            DISPLAYUPDATE(2, "\r%6u/%6u    ", testNb, nbTests);
         } else {
-            DISPLAYUPDATE(2, "\r%6u  (%08X)        ", testNb, coreSeed);
+            DISPLAYUPDATE(2, "\r%6u         ", testNb);
         }
         lseed = coreSeed ^ prime32;