feat(compress): move thread-pool attachment policy into Rust
Move ZSTD_CCtx_refThreadPool init-stage validation and pool-slot assignment behind a Rust-owned ABI bridge while keeping the opaque pool and CCtx storage in C. Preserve the stage error and avoid mutating the pool on rejection. Test Plan: - cargo test --manifest-path rust/Cargo.toml --lib - cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings - make -B -C programs -j1 zstd - make -C tests -j1 test-zstream ZSTREAM_TESTTIME=-T1s - focused ref_thread_pool unit tests
This commit is contained in:
@@ -287,6 +287,20 @@ typedef char ZSTD_rust_set_parameter_state_layout[
|
||||
== 4 * sizeof(void*)
|
||||
&& sizeof(ZSTD_rust_setParameterState) == 5 * sizeof(void*))
|
||||
? 1 : -1];
|
||||
/* Thread-pool attachment policy lives in Rust. The pool slot remains
|
||||
* C-owned; this projection passes its storage location and opaque value. */
|
||||
typedef struct {
|
||||
void** pool;
|
||||
void* requestedPool;
|
||||
int streamStage;
|
||||
} ZSTD_rust_refThreadPoolState;
|
||||
size_t ZSTD_rust_refThreadPool(const ZSTD_rust_refThreadPoolState* state);
|
||||
typedef char ZSTD_rust_ref_thread_pool_state_layout[
|
||||
(offsetof(ZSTD_rust_refThreadPoolState, pool) == 0
|
||||
&& offsetof(ZSTD_rust_refThreadPoolState, requestedPool) == sizeof(void*)
|
||||
&& offsetof(ZSTD_rust_refThreadPoolState, streamStage) == 2 * sizeof(void*)
|
||||
&& sizeof(ZSTD_rust_refThreadPoolState) == 3 * sizeof(void*))
|
||||
? 1 : -1];
|
||||
typedef void (*ZSTD_rust_resetCCtxClearAllDicts_f)(void* context);
|
||||
typedef size_t (*ZSTD_rust_resetCCtxResetParams_f)(void* context);
|
||||
typedef struct {
|
||||
@@ -2084,10 +2098,11 @@ size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict)
|
||||
|
||||
size_t ZSTD_CCtx_refThreadPool(ZSTD_CCtx* cctx, ZSTD_threadPool* pool)
|
||||
{
|
||||
RETURN_ERROR_IF(cctx->streamStage != zcss_init, stage_wrong,
|
||||
"Can't ref a pool when ctx not in init stage.");
|
||||
cctx->pool = pool;
|
||||
return 0;
|
||||
ZSTD_rust_refThreadPoolState state;
|
||||
state.pool = (void**)&cctx->pool;
|
||||
state.requestedPool = pool;
|
||||
state.streamStage = (int)cctx->streamStage;
|
||||
return ZSTD_rust_refThreadPool(&state);
|
||||
}
|
||||
|
||||
size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx, const void* prefix, size_t prefixSize)
|
||||
|
||||
Reference in New Issue
Block a user