refactor(mt): move stream reset ordering to Rust

Make Rust own the MT stream reset sequence through a narrow callback
projection. C retains the private buffer, job-ID, frame-flag, progress, and
sentinel mutations, preserving the original order without exposing private
layouts across the ABI.

Test Plan:
- rustfmt --edition 2021 --check rust/src/zstdmt_compress.rs
- git diff --check
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml --all-targets (786 passed)
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets -- -D warnings
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/cli/Cargo.toml --all-targets (179 passed)
- ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo +nightly fmt --manifest-path rust/Cargo.toml -- --check
- ulimit -v 41943040; make -j1
- ulimit -v 41943040; make -j1 -C tests test (all tests completed successfully)
This commit is contained in:
2026-07-20 07:31:23 +02:00
parent dc3c9c6c11
commit 429694a250
2 changed files with 214 additions and 10 deletions
+63 -10
View File
@@ -695,6 +695,25 @@ size_t ZSTDMT_rust_initCStream(
ZSTDMT_initResetStreamFn resetStream,
ZSTDMT_initDictionaryFn updateDictionary,
ZSTDMT_initSerialResetFn serialReset);
typedef void (*ZSTDMT_resetStreamCallbackFn)(void* opaque);
typedef struct {
void* callbackContext;
ZSTDMT_resetStreamCallbackFn resetRoundBuffer;
ZSTDMT_resetStreamCallbackFn resetInputBuffer;
ZSTDMT_resetStreamCallbackFn resetJobIDs;
ZSTDMT_resetStreamCallbackFn resetFrameFlags;
ZSTDMT_resetStreamCallbackFn resetProgress;
} ZSTDMT_RustResetStreamState;
typedef char ZSTDMT_rust_reset_stream_state_layout[
(sizeof(ZSTDMT_resetStreamCallbackFn) == sizeof(void*)
&& offsetof(ZSTDMT_RustResetStreamState, callbackContext) == 0
&& offsetof(ZSTDMT_RustResetStreamState, resetRoundBuffer) == sizeof(void*)
&& offsetof(ZSTDMT_RustResetStreamState, resetInputBuffer) == 2 * sizeof(void*)
&& offsetof(ZSTDMT_RustResetStreamState, resetJobIDs) == 3 * sizeof(void*)
&& offsetof(ZSTDMT_RustResetStreamState, resetFrameFlags) == 4 * sizeof(void*)
&& offsetof(ZSTDMT_RustResetStreamState, resetProgress) == 5 * sizeof(void*)
&& sizeof(ZSTDMT_RustResetStreamState) == 6 * sizeof(void*)) ? 1 : -1];
void ZSTDMT_rust_resetStream(const ZSTDMT_RustResetStreamState* state);
typedef struct {
void* callbackContext;
unsigned nbWorkers;
@@ -2377,21 +2396,55 @@ static size_t ZSTDMT_initCStreamResizeRoundBuffer(void* opaque, size_t capacity)
return 0;
}
static void ZSTDMT_initCStreamResetRoundBuffer(void* opaque)
{
ZSTDMT_initCStreamState* const state = (ZSTDMT_initCStreamState*)opaque;
state->mtctx->roundBuff.pos = 0;
}
static void ZSTDMT_initCStreamResetInputBuffer(void* opaque)
{
ZSTDMT_initCStreamState* const state = (ZSTDMT_initCStreamState*)opaque;
state->mtctx->inBuff.buffer = g_nullBuffer;
state->mtctx->inBuff.filled = 0;
state->mtctx->inBuff.prefix = kNullRange;
}
static void ZSTDMT_initCStreamResetJobIDs(void* opaque)
{
ZSTDMT_initCStreamState* const state = (ZSTDMT_initCStreamState*)opaque;
state->mtctx->doneJobID = 0;
state->mtctx->nextJobID = 0;
}
static void ZSTDMT_initCStreamResetFrameFlags(void* opaque)
{
ZSTDMT_initCStreamState* const state = (ZSTDMT_initCStreamState*)opaque;
state->mtctx->frameEnded = 0;
state->mtctx->allJobsCompleted = 0;
}
static void ZSTDMT_initCStreamResetProgress(void* opaque)
{
ZSTDMT_initCStreamState* const state = (ZSTDMT_initCStreamState*)opaque;
state->mtctx->consumed = 0;
state->mtctx->produced = 0;
}
static void ZSTDMT_initCStreamResetStream(void* opaque)
{
ZSTDMT_initCStreamState* const state = (ZSTDMT_initCStreamState*)opaque;
ZSTDMT_CCtx* const mtctx = state->mtctx;
ZSTDMT_RustResetStreamState const resetState = {
state,
ZSTDMT_initCStreamResetRoundBuffer,
ZSTDMT_initCStreamResetInputBuffer,
ZSTDMT_initCStreamResetJobIDs,
ZSTDMT_initCStreamResetFrameFlags,
ZSTDMT_initCStreamResetProgress
};
DEBUGLOG(4, "roundBuff capacity : %u KB", (U32)(mtctx->roundBuff.capacity >> 10));
mtctx->roundBuff.pos = 0;
mtctx->inBuff.buffer = g_nullBuffer;
mtctx->inBuff.filled = 0;
mtctx->inBuff.prefix = kNullRange;
mtctx->doneJobID = 0;
mtctx->nextJobID = 0;
mtctx->frameEnded = 0;
mtctx->allJobsCompleted = 0;
mtctx->consumed = 0;
mtctx->produced = 0;
ZSTDMT_rust_resetStream(&resetState);
}
static size_t ZSTDMT_initCStreamUpdateDictionary(void* opaque)