diff --git a/lib/compress/zstdmt_compress.c b/lib/compress/zstdmt_compress.c index 7021698d4..efbff5159 100644 --- a/lib/compress/zstdmt_compress.c +++ b/lib/compress/zstdmt_compress.c @@ -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; diff --git a/rust/src/zstdmt_compress.rs b/rust/src/zstdmt_compress.rs index 6999a0ea2..6354ceeef 100644 --- a/rust/src/zstdmt_compress.rs +++ b/rust/src/zstdmt_compress.rs @@ -1017,7 +1017,8 @@ pub type ZSTDMT_flushUpdateJobFn = unsafe extern "C" fn(opaque: *mut c_void, job_id: c_uint, dst_flushed: usize); pub type ZSTDMT_flushCompleteJobFn = unsafe extern "C" fn(opaque: *mut c_void, job_id: c_uint, src_size: usize, c_size: usize); -pub type ZSTDMT_flushErrorFn = unsafe extern "C" fn(opaque: *mut c_void); +pub type ZSTDMT_flushWaitForAllJobsFn = unsafe extern "C" fn(opaque: *mut c_void); +pub type ZSTDMT_flushReleaseAllJobResourcesFn = unsafe extern "C" fn(opaque: *mut c_void); /// Scalar MT state used by the outer streaming scheduler. The C context, /// input-range ownership, and synchronization objects remain private to C; @@ -2337,7 +2338,7 @@ fn flush_produced_result(result: usize, output_pos: usize) -> ZSTDMT_flushProduc } #[inline] -unsafe fn flush_produced_with
( +unsafe fn flush_produced_with
( context: ZSTDMT_flushContextProjection, output_dst: *mut c_void, output_size: usize, @@ -2348,14 +2349,16 @@ unsafe fn flush_produced_with
(
mut add_frame_checksum: C,
mut update_job: U,
mut complete_job: F,
- mut on_error: E,
+ mut wait_for_all_jobs: W,
+ mut release_all_job_resources: R,
) -> ZSTDMT_flushProducedResult
where
P: FnMut(c_uint, c_uint) -> ZSTDMT_flushJobProjection,
C: FnMut(c_uint, &mut ZSTDMT_flushJobProjection),
U: FnMut(c_uint, usize),
F: FnMut(c_uint, usize, usize),
- E: FnMut(),
+ W: FnMut(),
+ R: FnMut(),
{
let mut output_pos = output_pos;
let mut done_job_id = context.doneJobID;
@@ -2367,7 +2370,8 @@ where
let src_size = projection.srcSize;
if ERR_isError(projection.cSize) {
- on_error();
+ wait_for_all_jobs();
+ release_all_job_resources();
return flush_produced_result(projection.cSize, output_pos);
}
@@ -2379,7 +2383,8 @@ where
}
if ERR_isError(projection.cSize) {
- on_error();
+ wait_for_all_jobs();
+ release_all_job_resources();
return flush_produced_result(projection.cSize, output_pos);
}
@@ -2612,7 +2617,8 @@ pub unsafe extern "C" fn ZSTDMT_rust_flushProduced(
addFrameChecksum: Option