feat(compress): port MT job-table expansion orchestration
ZSTDMT_expandJobsTable previously kept worker-capacity comparison, old-table synchronization teardown, replacement allocation, initialization failure cleanup, and mask updates in C. That left the remaining job-table lifecycle orchestration outside the Rust storage leaves. Add a narrow Rust ABI that exchanges only opaque storage and scalar mask state and accepts C callbacks for the private synchronization lifecycle. The adapter frees the old table before replacement, reuses the existing Rust create/free leaves with the caller's custom memory, destroys a partially initialized replacement before freeing it, and updates jobIDMask only after successful initialization. C still owns ZSTDMT_CCtx and job descriptors, so worker-facing fields and platform synchronization stay outside the Rust ABI. Test Plan: - `cargo test --manifest-path rust/Cargo.toml --no-default-features --features compression zstdmt_compress --lib` -- 38 passed. - `cargo clippy`, `cargo clippy --benches`, and `cargo clippy --tests` -- passed. - `cargo +nightly fmt --all -- --check` -- passed. - `make -B -C lib lib-mt` -- passed. - `make -B -C tests -j2 fullbench poolTests` -- passed. - `./poolTests` and `./fullbench -i1 -B1000 ../README.md` -- passed.
This commit is contained in:
@@ -163,6 +163,15 @@ ZSTD_frameProgression ZSTDMT_rust_frameProgression(
|
||||
ZSTD_frameProgression ZSTDMT_rust_frameProgressionAddJob(
|
||||
ZSTD_frameProgression progression, size_t srcSize, size_t consumed,
|
||||
size_t produced, size_t flushed);
|
||||
typedef int (*ZSTDMT_jobTableInitFn)(void* jobTable, unsigned nbJobs,
|
||||
size_t jobSize);
|
||||
typedef void (*ZSTDMT_jobTableDestroyFn)(void* jobTable, unsigned nbJobs,
|
||||
size_t jobSize);
|
||||
size_t ZSTDMT_rust_expandJobsTable(
|
||||
void** jobTablePtr, unsigned* jobIDMaskPtr, unsigned nbWorkers,
|
||||
size_t jobSize, ZSTD_customMem cMem,
|
||||
ZSTDMT_jobTableInitFn initSync,
|
||||
ZSTDMT_jobTableDestroyFn destroySync);
|
||||
|
||||
typedef struct ZSTDMT_bufferPool_s {
|
||||
ZSTDMT_RustBufferPool* rustPool;
|
||||
@@ -911,16 +920,14 @@ static ZSTDMT_jobDescription* ZSTDMT_createJobsTable(U32* nbJobsPtr, ZSTD_custom
|
||||
}
|
||||
|
||||
static size_t ZSTDMT_expandJobsTable (ZSTDMT_CCtx* mtctx, U32 nbWorkers) {
|
||||
U32 nbJobs = nbWorkers + 2;
|
||||
if (nbJobs > mtctx->jobIDMask+1) { /* need more job capacity */
|
||||
ZSTDMT_freeJobsTable(mtctx->jobs, mtctx->jobIDMask+1, mtctx->cMem);
|
||||
mtctx->jobIDMask = 0;
|
||||
mtctx->jobs = ZSTDMT_createJobsTable(&nbJobs, mtctx->cMem);
|
||||
if (mtctx->jobs==NULL) return ERROR(memory_allocation);
|
||||
assert((nbJobs != 0) && ((nbJobs & (nbJobs - 1)) == 0)); /* ensure nbJobs is a power of 2 */
|
||||
mtctx->jobIDMask = nbJobs - 1;
|
||||
}
|
||||
return 0;
|
||||
void* jobs = mtctx->jobs;
|
||||
U32 jobIDMask = mtctx->jobIDMask;
|
||||
size_t const error = ZSTDMT_rust_expandJobsTable(
|
||||
&jobs, &jobIDMask, nbWorkers, sizeof(ZSTDMT_jobDescription),
|
||||
mtctx->cMem, ZSTDMT_job_table_init_sync, ZSTDMT_job_table_destroy_sync);
|
||||
mtctx->jobs = (ZSTDMT_jobDescription*)jobs;
|
||||
mtctx->jobIDMask = jobIDMask;
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user