refactor(compress): move toFlushNow policy to Rust

Move the worker-count branch of ZSTD_toFlushNow into the Rust policy layer.
The C adapter retains the private CCtx and multithread context, exposing only
the worker count and a callback for the MT flush query.  Single-threaded
contexts keep the existing zero result and the ABI projection is checked on
both sides.

Test Plan:
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml to_flush_now --lib
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings
- ulimit -v 41943040; make -j1
This commit is contained in:
2026-07-20 04:49:18 +02:00
parent dc83c98f06
commit 6d164b7746
2 changed files with 92 additions and 7 deletions
+29 -7
View File
@@ -4020,18 +4020,40 @@ ZSTD_frameProgression ZSTD_getFrameProgression(const ZSTD_CCtx* cctx)
cctx->producedCSize);
} }
typedef size_t (*ZSTD_rust_toFlushNow_f)(void* context);
typedef struct {
void* callbackContext;
int nbWorkers;
ZSTD_rust_toFlushNow_f toFlushNow;
} ZSTD_rust_toFlushNowState;
typedef char ZSTD_rust_to_flush_now_state_layout[
(offsetof(ZSTD_rust_toFlushNowState, callbackContext) == 0
&& offsetof(ZSTD_rust_toFlushNowState, nbWorkers) == sizeof(void*)
&& offsetof(ZSTD_rust_toFlushNowState, toFlushNow) == 2 * sizeof(void*)
&& sizeof(ZSTD_rust_toFlushNowState) == 3 * sizeof(void*))
? 1 : -1];
size_t ZSTD_rust_toFlushNow(const ZSTD_rust_toFlushNowState* state);
static size_t ZSTD_rust_toFlushNow_callback(void* context)
{
#ifdef ZSTD_MULTITHREAD
return ZSTDMT_toFlushNow(((ZSTD_CCtx*)context)->mtctx);
#else
(void)context;
return 0;
#endif
}
/*! ZSTD_toFlushNow()
* Only useful for multithreading scenarios currently (nbWorkers >= 1).
*/
size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx)
{
#ifdef ZSTD_MULTITHREAD
if (cctx->appliedParams.nbWorkers > 0) {
return ZSTDMT_toFlushNow(cctx->mtctx);
}
#endif
(void)cctx;
return 0; /* over-simplification; could also check if context is currently running in streaming mode, and in which case, report how many bytes are left to be flushed within output buffer */
ZSTD_rust_toFlushNowState state;
state.callbackContext = cctx;
state.nbWorkers = (int)cctx->appliedParams.nbWorkers;
state.toFlushNow = ZSTD_rust_toFlushNow_callback;
return ZSTD_rust_toFlushNow(&state);
}
static void ZSTD_assertEqualCParams(ZSTD_compressionParameters cParams1,