2017-08-18 16:52:05 -07:00
|
|
|
/*
|
2022-12-20 12:49:47 -05:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2017-01-20 14:00:41 -08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2017-08-18 16:52:05 -07:00
|
|
|
* This source code is licensed under both the BSD-style license (found in the
|
|
|
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
|
|
* in the COPYING file in the root directory of this source tree).
|
2017-09-08 00:09:23 -07:00
|
|
|
* You may select, at your option, one of the above-listed licenses.
|
2017-01-20 14:00:41 -08:00
|
|
|
*/
|
2016-12-27 07:19:36 +01:00
|
|
|
|
2017-01-27 16:00:19 -08:00
|
|
|
#ifndef ZSTDMT_COMPRESS_H
|
|
|
|
#define ZSTDMT_COMPRESS_H
|
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-01-24 17:02:26 -08:00
|
|
|
|
2017-07-05 17:20:52 -07:00
|
|
|
/* Note : This is an internal API.
|
2019-04-07 18:47:52 -07:00
|
|
|
* These APIs used to be exposed with ZSTDLIB_API,
|
2017-07-11 17:18:26 -07:00
|
|
|
* because it used to be the only way to invoke MT compression.
|
2020-10-01 18:47:54 -07:00
|
|
|
* Now, you must use ZSTD_compress2 and ZSTD_compressStream2() instead.
|
2019-04-15 22:49:44 -07:00
|
|
|
*
|
|
|
|
* This API requires ZSTD_MULTITHREAD to be defined during compilation,
|
|
|
|
* otherwise ZSTDMT_createCCtx*() will fail.
|
2019-04-07 18:47:52 -07:00
|
|
|
*/
|
|
|
|
|
2017-01-12 01:25:46 +01:00
|
|
|
/* === Dependencies === */
|
2020-08-06 20:18:05 -07:00
|
|
|
#include "../common/zstd_deps.h" /* size_t */
|
2017-01-19 15:32:07 -08:00
|
|
|
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters */
|
2020-05-01 16:07:57 -04:00
|
|
|
#include "../zstd.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTDLIB_API */
|
2016-12-27 07:19:36 +01:00
|
|
|
|
|
|
|
|
2018-11-20 15:13:27 -08:00
|
|
|
/* === Constants === */
|
2021-05-12 13:10:25 -07:00
|
|
|
#ifndef ZSTDMT_NBWORKERS_MAX /* a different value can be selected at compile time */
|
|
|
|
# define ZSTDMT_NBWORKERS_MAX ((sizeof(void*)==4) /*32-bit*/ ? 64 : 256)
|
2018-12-11 17:41:42 -08:00
|
|
|
#endif
|
2021-05-12 13:10:25 -07:00
|
|
|
#ifndef ZSTDMT_JOBSIZE_MIN /* a different value can be selected at compile time */
|
2021-05-04 10:54:34 -07:00
|
|
|
# define ZSTDMT_JOBSIZE_MIN (512 KB)
|
2018-11-20 16:06:00 -08:00
|
|
|
#endif
|
2019-07-12 18:45:18 -04:00
|
|
|
#define ZSTDMT_JOBLOG_MAX (MEM_32bits() ? 29 : 30)
|
2018-12-13 12:14:36 -08:00
|
|
|
#define ZSTDMT_JOBSIZE_MAX (MEM_32bits() ? (512 MB) : (1024 MB))
|
2018-11-20 15:13:27 -08:00
|
|
|
|
|
|
|
|
2020-10-01 18:47:54 -07:00
|
|
|
/* ========================================================
|
|
|
|
* === Private interface, for use by ZSTD_compress.c ===
|
|
|
|
* === Not exposed in libzstd. Never invoke directly ===
|
|
|
|
* ======================================================== */
|
|
|
|
|
2017-06-01 17:56:14 -07:00
|
|
|
/* === Memory management === */
|
2017-01-12 01:25:46 +01:00
|
|
|
typedef struct ZSTDMT_CCtx_s ZSTDMT_CCtx;
|
2019-04-15 22:49:44 -07:00
|
|
|
/* Requires ZSTD_MULTITHREAD to be defined during compilation, otherwise it will return NULL. */
|
2020-10-01 18:47:54 -07:00
|
|
|
ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced(unsigned nbWorkers,
|
|
|
|
ZSTD_customMem cMem,
|
|
|
|
ZSTD_threadPool *pool);
|
|
|
|
size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx* mtctx);
|
2017-01-12 01:25:46 +01:00
|
|
|
|
2020-10-01 18:47:54 -07:00
|
|
|
size_t ZSTDMT_sizeof_CCtx(ZSTDMT_CCtx* mtctx);
|
2017-06-30 14:51:01 -07:00
|
|
|
|
2017-01-12 01:25:46 +01:00
|
|
|
/* === Streaming functions === */
|
|
|
|
|
2020-10-01 18:47:54 -07:00
|
|
|
size_t ZSTDMT_nextInputSizeHint(const ZSTDMT_CCtx* mtctx);
|
2018-06-25 15:21:08 -07:00
|
|
|
|
2020-10-01 18:47:54 -07:00
|
|
|
/*! ZSTDMT_initCStream_internal() :
|
|
|
|
* Private use only. Init streaming operation.
|
|
|
|
* expects params to be valid.
|
|
|
|
* must receive dict, or cdict, or none, but not both.
|
2022-01-14 11:11:41 -07:00
|
|
|
* mtctx can be freshly constructed or reused from a prior compression.
|
|
|
|
* If mtctx is reused, memory allocations from the prior compression may not be freed,
|
|
|
|
* even if they are not needed for the current compression.
|
2020-10-01 18:47:54 -07:00
|
|
|
* @return : 0, or an error code */
|
2022-01-14 11:11:41 -07:00
|
|
|
size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx* mtctx,
|
2020-10-01 18:47:54 -07:00
|
|
|
const void* dict, size_t dictSize, ZSTD_dictContentType_e dictContentType,
|
|
|
|
const ZSTD_CDict* cdict,
|
|
|
|
ZSTD_CCtx_params params, unsigned long long pledgedSrcSize);
|
2017-01-27 16:00:19 -08:00
|
|
|
|
2017-06-05 18:32:48 -07:00
|
|
|
/*! ZSTDMT_compressStream_generic() :
|
2018-01-19 22:11:11 -08:00
|
|
|
* Combines ZSTDMT_compressStream() with optional ZSTDMT_flushStream() or ZSTDMT_endStream()
|
2017-06-20 14:11:49 -07:00
|
|
|
* depending on flush directive.
|
2017-06-05 18:32:48 -07:00
|
|
|
* @return : minimum amount of data still to be flushed
|
|
|
|
* 0 if fully flushed
|
2018-01-19 22:11:11 -08:00
|
|
|
* or an error code
|
|
|
|
* note : needs to be init using any ZSTD_initCStream*() variant */
|
2020-10-01 18:47:54 -07:00
|
|
|
size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx,
|
|
|
|
ZSTD_outBuffer* output,
|
|
|
|
ZSTD_inBuffer* input,
|
|
|
|
ZSTD_EndDirective endOp);
|
2017-09-11 14:09:34 -07:00
|
|
|
|
2018-08-17 18:11:54 -07:00
|
|
|
/*! ZSTDMT_toFlushNow()
|
|
|
|
* Tell how many bytes are ready to be flushed immediately.
|
|
|
|
* Probe the oldest active job (not yet entirely flushed) and check its output buffer.
|
|
|
|
* If return 0, it means there is no active job,
|
|
|
|
* or, it means oldest job is still active, but everything produced has been flushed so far,
|
|
|
|
* therefore flushing is limited by speed of oldest job. */
|
|
|
|
size_t ZSTDMT_toFlushNow(ZSTDMT_CCtx* mtctx);
|
|
|
|
|
2018-02-02 15:58:13 -08:00
|
|
|
/*! ZSTDMT_updateCParams_whileCompressing() :
|
2018-03-19 14:41:23 -07:00
|
|
|
* Updates only a selected set of compression parameters, to remain compatible with current frame.
|
2018-02-02 14:24:56 -08:00
|
|
|
* New parameters will be applied to next compression job. */
|
2018-03-19 14:41:23 -07:00
|
|
|
void ZSTDMT_updateCParams_whileCompressing(ZSTDMT_CCtx* mtctx, const ZSTD_CCtx_params* cctxParams);
|
2018-02-01 16:13:31 -08:00
|
|
|
|
2018-08-17 18:11:54 -07:00
|
|
|
/*! ZSTDMT_getFrameProgression():
|
|
|
|
* tells how much data has been consumed (input) and produced (output) for current frame.
|
|
|
|
* able to count progression inside worker threads.
|
2018-01-17 16:39:02 -08:00
|
|
|
*/
|
|
|
|
ZSTD_frameProgression ZSTDMT_getFrameProgression(ZSTDMT_CCtx* mtctx);
|
|
|
|
|
|
|
|
|
2017-01-27 16:00:19 -08:00
|
|
|
#if defined (__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* ZSTDMT_COMPRESS_H */
|