feat(compress): split MT stream drain policy
The MT stream initializer previously exposed one C callback that waited for all submitted jobs and then released their resources. That left the ordering policy in C even though Rust already owned the surrounding initialization sequence and the ring-order wait/release policies. Expose separate wait-all and release-all callbacks at the Rust/C boundary and invoke them in Rust in the original wait-before-release order. C retains the worker synchronization, job descriptors, input buffer, and resource-pool side effects behind the two callbacks, while the focused Rust initializer test now makes the ordering explicit. Test Plan: - capped cargo +nightly fmt for the Rust workspace -- passed - capped root cargo clippy --all-targets -- -D warnings -- passed - capped serial make -j1 for the single-threaded library, MT library, and CLI -- passed - git diff --cached --check -- passed
This commit is contained in:
@@ -756,7 +756,8 @@ typedef struct {
|
||||
unsigned allJobsCompleted;
|
||||
} ZSTDMT_RustInitCStreamProjection;
|
||||
typedef size_t (*ZSTDMT_initResizeFn)(void* opaque, unsigned nbWorkers);
|
||||
typedef void (*ZSTDMT_initDrainFn)(void* opaque);
|
||||
typedef void (*ZSTDMT_initWaitForAllJobsFn)(void* opaque);
|
||||
typedef void (*ZSTDMT_initReleaseAllJobResourcesFn)(void* opaque);
|
||||
typedef void (*ZSTDMT_initApplyParametersFn)(void* opaque, size_t jobSize);
|
||||
typedef size_t (*ZSTDMT_initDictionaryFn)(void* opaque);
|
||||
typedef void (*ZSTDMT_initSetSizeFn)(void* opaque, size_t size);
|
||||
@@ -938,7 +939,9 @@ void* ZSTDMT_rust_createCCtx(
|
||||
ZSTDMT_createCCtxFreeFn freeContext);
|
||||
size_t ZSTDMT_rust_initCStream(
|
||||
const ZSTDMT_RustInitCStreamProjection* projection, void* opaque,
|
||||
ZSTDMT_initResizeFn resize, ZSTDMT_initDrainFn drain,
|
||||
ZSTDMT_initResizeFn resize,
|
||||
ZSTDMT_initWaitForAllJobsFn waitForAllJobs,
|
||||
ZSTDMT_initReleaseAllJobResourcesFn releaseAllJobResources,
|
||||
ZSTDMT_initApplyParametersFn applyParameters,
|
||||
ZSTDMT_initDictionaryFn prepareDictionary,
|
||||
ZSTDMT_initSetSizeFn setTargetPrefixSize,
|
||||
@@ -2782,13 +2785,16 @@ static size_t ZSTDMT_initCStreamResize(void* opaque, unsigned nbWorkers)
|
||||
return ZSTDMT_resize(state->mtctx, nbWorkers);
|
||||
}
|
||||
|
||||
static void ZSTDMT_initCStreamDrain(void* opaque)
|
||||
static void ZSTDMT_initCStreamWaitForAllJobs(void* opaque)
|
||||
{
|
||||
ZSTDMT_initCStreamState* const state = (ZSTDMT_initCStreamState*)opaque;
|
||||
ZSTDMT_CCtx* const mtctx = state->mtctx;
|
||||
ZSTDMT_waitForAllJobsCompleted(mtctx);
|
||||
ZSTDMT_releaseAllJobResources(mtctx);
|
||||
mtctx->allJobsCompleted = 1;
|
||||
ZSTDMT_waitForAllJobsCompleted(state->mtctx);
|
||||
}
|
||||
|
||||
static void ZSTDMT_initCStreamReleaseAllJobResources(void* opaque)
|
||||
{
|
||||
ZSTDMT_initCStreamState* const state = (ZSTDMT_initCStreamState*)opaque;
|
||||
ZSTDMT_releaseAllJobResources(state->mtctx);
|
||||
}
|
||||
|
||||
static void ZSTDMT_initCStreamApplyParameters(void* opaque, size_t jobSize)
|
||||
@@ -3031,7 +3037,8 @@ size_t ZSTDMT_initCStream_internal(
|
||||
return ZSTDMT_rust_initCStream(
|
||||
&projection, &state,
|
||||
ZSTDMT_initCStreamResize,
|
||||
ZSTDMT_initCStreamDrain,
|
||||
ZSTDMT_initCStreamWaitForAllJobs,
|
||||
ZSTDMT_initCStreamReleaseAllJobResources,
|
||||
ZSTDMT_initCStreamApplyParameters,
|
||||
ZSTDMT_initCStreamPrepareDictionary,
|
||||
ZSTDMT_initCStreamSetTargetPrefixSize,
|
||||
|
||||
Reference in New Issue
Block a user