feat(mt): move flush error cleanup order into Rust
The MT flush state machine already recognized worker and checksum errors in Rust, but its single C error callback still bundled waiting for all workers with releasing job resources. That kept teardown order in C and made the two cleanup phases impossible to test independently. Split the C callback into private wait and release leaves, then pass both to Rust. Rust now owns the error cleanup sequence and always waits for workers before releasing their resources on either error path. The MT context, job resources, synchronization, and cleanup operations remain C-owned. Test Plan: - `rustup run nightly rustfmt --check --edition 2021 rust/src/zstdmt_compress.rs` -- passed under the 40 GiB virtual-memory cap. - `cc -fsyntax-only -std=c99` with the zstd include paths for `lib/compress/zstdmt_compress.c` -- passed under the cap. - `git diff --check` and `git diff --cached --check` -- passed. - Cargo, Make, native builds, fuzzers, and large tests were not run per the worker OOM and scope constraints.
This commit is contained in:
@@ -357,7 +357,8 @@ typedef void (*ZSTDMT_flushUpdateJobFn)(
|
||||
void* opaque, unsigned jobID, size_t dstFlushed);
|
||||
typedef void (*ZSTDMT_flushCompleteJobFn)(
|
||||
void* opaque, unsigned jobID, size_t srcSize, size_t cSize);
|
||||
typedef void (*ZSTDMT_flushErrorFn)(void* opaque);
|
||||
typedef void (*ZSTDMT_flushWaitForAllJobsFn)(void* opaque);
|
||||
typedef void (*ZSTDMT_flushReleaseAllJobResourcesFn)(void* opaque);
|
||||
ZSTDMT_RustFlushProducedResult ZSTDMT_rust_flushProduced(
|
||||
const ZSTDMT_RustFlushContextProjection* context,
|
||||
void* outputDst, size_t outputSize, size_t outputPos,
|
||||
@@ -366,7 +367,8 @@ ZSTDMT_RustFlushProducedResult ZSTDMT_rust_flushProduced(
|
||||
ZSTDMT_flushChecksumFn addFrameChecksum,
|
||||
ZSTDMT_flushUpdateJobFn updateJob,
|
||||
ZSTDMT_flushCompleteJobFn completeJob,
|
||||
ZSTDMT_flushErrorFn onError);
|
||||
ZSTDMT_flushWaitForAllJobsFn waitForAllJobs,
|
||||
ZSTDMT_flushReleaseAllJobResourcesFn releaseAllJobResources);
|
||||
size_t ZSTDMT_rust_writeFrameChecksum(
|
||||
const ZSTDMT_RustFrameChecksumProjection* projection);
|
||||
|
||||
@@ -2937,10 +2939,15 @@ static void ZSTDMT_completeFlushJob(void* opaque, unsigned jobID,
|
||||
mtctx->doneJobID++;
|
||||
}
|
||||
|
||||
static void ZSTDMT_flushError(void* opaque)
|
||||
static void ZSTDMT_flushWaitForAllJobs(void* opaque)
|
||||
{
|
||||
ZSTDMT_CCtx* const mtctx = (ZSTDMT_CCtx*)opaque;
|
||||
ZSTDMT_waitForAllJobsCompleted(mtctx);
|
||||
}
|
||||
|
||||
static void ZSTDMT_flushReleaseAllJobResources(void* opaque)
|
||||
{
|
||||
ZSTDMT_CCtx* const mtctx = (ZSTDMT_CCtx*)opaque;
|
||||
ZSTDMT_releaseAllJobResources(mtctx);
|
||||
}
|
||||
|
||||
@@ -2968,7 +2975,8 @@ static size_t ZSTDMT_flushProduced(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output, u
|
||||
ZSTDMT_addFrameChecksum,
|
||||
ZSTDMT_updateFlushJob,
|
||||
ZSTDMT_completeFlushJob,
|
||||
ZSTDMT_flushError);
|
||||
ZSTDMT_flushWaitForAllJobs,
|
||||
ZSTDMT_flushReleaseAllJobResources);
|
||||
|
||||
assert(output->size >= output->pos);
|
||||
output->pos = result.outputPos;
|
||||
|
||||
Reference in New Issue
Block a user