Path: blob/master/Utilities/cmzstd/lib/compress/zstdmt_compress.h
4997 views
/*1* Copyright (c) Meta Platforms, Inc. and affiliates.2* All rights reserved.3*4* This source code is licensed under both the BSD-style license (found in the5* LICENSE file in the root directory of this source tree) and the GPLv2 (found6* in the COPYING file in the root directory of this source tree).7* You may select, at your option, one of the above-listed licenses.8*/910#ifndef ZSTDMT_COMPRESS_H11#define ZSTDMT_COMPRESS_H1213/* === Dependencies === */14#include "../common/zstd_deps.h" /* size_t */15#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters */16#include "../zstd.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTDLIB_API */1718/* Note : This is an internal API.19* These APIs used to be exposed with ZSTDLIB_API,20* because it used to be the only way to invoke MT compression.21* Now, you must use ZSTD_compress2 and ZSTD_compressStream2() instead.22*23* This API requires ZSTD_MULTITHREAD to be defined during compilation,24* otherwise ZSTDMT_createCCtx*() will fail.25*/2627/* === Constants === */28#ifndef ZSTDMT_NBWORKERS_MAX /* a different value can be selected at compile time */29# define ZSTDMT_NBWORKERS_MAX ((sizeof(void*)==4) /*32-bit*/ ? 64 : 256)30#endif31#ifndef ZSTDMT_JOBSIZE_MIN /* a different value can be selected at compile time */32# define ZSTDMT_JOBSIZE_MIN (512 KB)33#endif34#define ZSTDMT_JOBLOG_MAX (MEM_32bits() ? 29 : 30)35#define ZSTDMT_JOBSIZE_MAX (MEM_32bits() ? (512 MB) : (1024 MB))363738/* ========================================================39* === Private interface, for use by ZSTD_compress.c ===40* === Not exposed in libzstd. Never invoke directly ===41* ======================================================== */4243/* === Memory management === */44typedef struct ZSTDMT_CCtx_s ZSTDMT_CCtx;45/* Requires ZSTD_MULTITHREAD to be defined during compilation, otherwise it will return NULL. */46ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced(unsigned nbWorkers,47ZSTD_customMem cMem,48ZSTD_threadPool *pool);49size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx* mtctx);5051size_t ZSTDMT_sizeof_CCtx(ZSTDMT_CCtx* mtctx);5253/* === Streaming functions === */5455size_t ZSTDMT_nextInputSizeHint(const ZSTDMT_CCtx* mtctx);5657/*! ZSTDMT_initCStream_internal() :58* Private use only. Init streaming operation.59* expects params to be valid.60* must receive dict, or cdict, or none, but not both.61* mtctx can be freshly constructed or reused from a prior compression.62* If mtctx is reused, memory allocations from the prior compression may not be freed,63* even if they are not needed for the current compression.64* @return : 0, or an error code */65size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx* mtctx,66const void* dict, size_t dictSize, ZSTD_dictContentType_e dictContentType,67const ZSTD_CDict* cdict,68ZSTD_CCtx_params params, unsigned long long pledgedSrcSize);6970/*! ZSTDMT_compressStream_generic() :71* Combines ZSTDMT_compressStream() with optional ZSTDMT_flushStream() or ZSTDMT_endStream()72* depending on flush directive.73* @return : minimum amount of data still to be flushed74* 0 if fully flushed75* or an error code76* note : needs to be init using any ZSTD_initCStream*() variant */77size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx,78ZSTD_outBuffer* output,79ZSTD_inBuffer* input,80ZSTD_EndDirective endOp);8182/*! ZSTDMT_toFlushNow()83* Tell how many bytes are ready to be flushed immediately.84* Probe the oldest active job (not yet entirely flushed) and check its output buffer.85* If return 0, it means there is no active job,86* or, it means oldest job is still active, but everything produced has been flushed so far,87* therefore flushing is limited by speed of oldest job. */88size_t ZSTDMT_toFlushNow(ZSTDMT_CCtx* mtctx);8990/*! ZSTDMT_updateCParams_whileCompressing() :91* Updates only a selected set of compression parameters, to remain compatible with current frame.92* New parameters will be applied to next compression job. */93void ZSTDMT_updateCParams_whileCompressing(ZSTDMT_CCtx* mtctx, const ZSTD_CCtx_params* cctxParams);9495/*! ZSTDMT_getFrameProgression():96* tells how much data has been consumed (input) and produced (output) for current frame.97* able to count progression inside worker threads.98*/99ZSTD_frameProgression ZSTDMT_getFrameProgression(ZSTDMT_CCtx* mtctx);100101#endif /* ZSTDMT_COMPRESS_H */102103104