xref: /netbsd-src/external/bsd/zstd/dist/lib/compress/zstdmt_compress.h (revision 3117ece4fc4a4ca4489ba793710b60b0d26bab6c)
1*3117ece4Schristos /*
2*3117ece4Schristos  * Copyright (c) Meta Platforms, Inc. and affiliates.
3*3117ece4Schristos  * All rights reserved.
4*3117ece4Schristos  *
5*3117ece4Schristos  * This source code is licensed under both the BSD-style license (found in the
6*3117ece4Schristos  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7*3117ece4Schristos  * in the COPYING file in the root directory of this source tree).
8*3117ece4Schristos  * You may select, at your option, one of the above-listed licenses.
9*3117ece4Schristos  */
10*3117ece4Schristos 
11*3117ece4Schristos  #ifndef ZSTDMT_COMPRESS_H
12*3117ece4Schristos  #define ZSTDMT_COMPRESS_H
13*3117ece4Schristos 
14*3117ece4Schristos  #if defined (__cplusplus)
15*3117ece4Schristos  extern "C" {
16*3117ece4Schristos  #endif
17*3117ece4Schristos 
18*3117ece4Schristos 
19*3117ece4Schristos /* Note : This is an internal API.
20*3117ece4Schristos  *        These APIs used to be exposed with ZSTDLIB_API,
21*3117ece4Schristos  *        because it used to be the only way to invoke MT compression.
22*3117ece4Schristos  *        Now, you must use ZSTD_compress2 and ZSTD_compressStream2() instead.
23*3117ece4Schristos  *
24*3117ece4Schristos  *        This API requires ZSTD_MULTITHREAD to be defined during compilation,
25*3117ece4Schristos  *        otherwise ZSTDMT_createCCtx*() will fail.
26*3117ece4Schristos  */
27*3117ece4Schristos 
28*3117ece4Schristos /* ===   Dependencies   === */
29*3117ece4Schristos #include "../common/zstd_deps.h"   /* size_t */
30*3117ece4Schristos #define ZSTD_STATIC_LINKING_ONLY   /* ZSTD_parameters */
31*3117ece4Schristos #include "../zstd.h"            /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTDLIB_API */
32*3117ece4Schristos 
33*3117ece4Schristos 
34*3117ece4Schristos /* ===   Constants   === */
35*3117ece4Schristos #ifndef ZSTDMT_NBWORKERS_MAX /* a different value can be selected at compile time */
36*3117ece4Schristos #  define ZSTDMT_NBWORKERS_MAX ((sizeof(void*)==4) /*32-bit*/ ? 64 : 256)
37*3117ece4Schristos #endif
38*3117ece4Schristos #ifndef ZSTDMT_JOBSIZE_MIN   /* a different value can be selected at compile time */
39*3117ece4Schristos #  define ZSTDMT_JOBSIZE_MIN (512 KB)
40*3117ece4Schristos #endif
41*3117ece4Schristos #define ZSTDMT_JOBLOG_MAX   (MEM_32bits() ? 29 : 30)
42*3117ece4Schristos #define ZSTDMT_JOBSIZE_MAX  (MEM_32bits() ? (512 MB) : (1024 MB))
43*3117ece4Schristos 
44*3117ece4Schristos 
45*3117ece4Schristos /* ========================================================
46*3117ece4Schristos  * ===  Private interface, for use by ZSTD_compress.c   ===
47*3117ece4Schristos  * ===  Not exposed in libzstd. Never invoke directly   ===
48*3117ece4Schristos  * ======================================================== */
49*3117ece4Schristos 
50*3117ece4Schristos /* ===   Memory management   === */
51*3117ece4Schristos typedef struct ZSTDMT_CCtx_s ZSTDMT_CCtx;
52*3117ece4Schristos /* Requires ZSTD_MULTITHREAD to be defined during compilation, otherwise it will return NULL. */
53*3117ece4Schristos ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced(unsigned nbWorkers,
54*3117ece4Schristos                                         ZSTD_customMem cMem,
55*3117ece4Schristos 					ZSTD_threadPool *pool);
56*3117ece4Schristos size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx* mtctx);
57*3117ece4Schristos 
58*3117ece4Schristos size_t ZSTDMT_sizeof_CCtx(ZSTDMT_CCtx* mtctx);
59*3117ece4Schristos 
60*3117ece4Schristos /* ===   Streaming functions   === */
61*3117ece4Schristos 
62*3117ece4Schristos size_t ZSTDMT_nextInputSizeHint(const ZSTDMT_CCtx* mtctx);
63*3117ece4Schristos 
64*3117ece4Schristos /*! ZSTDMT_initCStream_internal() :
65*3117ece4Schristos  *  Private use only. Init streaming operation.
66*3117ece4Schristos  *  expects params to be valid.
67*3117ece4Schristos  *  must receive dict, or cdict, or none, but not both.
68*3117ece4Schristos  *  mtctx can be freshly constructed or reused from a prior compression.
69*3117ece4Schristos  *  If mtctx is reused, memory allocations from the prior compression may not be freed,
70*3117ece4Schristos  *  even if they are not needed for the current compression.
71*3117ece4Schristos  *  @return : 0, or an error code */
72*3117ece4Schristos size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx* mtctx,
73*3117ece4Schristos                     const void* dict, size_t dictSize, ZSTD_dictContentType_e dictContentType,
74*3117ece4Schristos                     const ZSTD_CDict* cdict,
75*3117ece4Schristos                     ZSTD_CCtx_params params, unsigned long long pledgedSrcSize);
76*3117ece4Schristos 
77*3117ece4Schristos /*! ZSTDMT_compressStream_generic() :
78*3117ece4Schristos  *  Combines ZSTDMT_compressStream() with optional ZSTDMT_flushStream() or ZSTDMT_endStream()
79*3117ece4Schristos  *  depending on flush directive.
80*3117ece4Schristos  * @return : minimum amount of data still to be flushed
81*3117ece4Schristos  *           0 if fully flushed
82*3117ece4Schristos  *           or an error code
83*3117ece4Schristos  *  note : needs to be init using any ZSTD_initCStream*() variant */
84*3117ece4Schristos size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx,
85*3117ece4Schristos                                      ZSTD_outBuffer* output,
86*3117ece4Schristos                                      ZSTD_inBuffer* input,
87*3117ece4Schristos                                      ZSTD_EndDirective endOp);
88*3117ece4Schristos 
89*3117ece4Schristos  /*! ZSTDMT_toFlushNow()
90*3117ece4Schristos   *  Tell how many bytes are ready to be flushed immediately.
91*3117ece4Schristos   *  Probe the oldest active job (not yet entirely flushed) and check its output buffer.
92*3117ece4Schristos   *  If return 0, it means there is no active job,
93*3117ece4Schristos   *  or, it means oldest job is still active, but everything produced has been flushed so far,
94*3117ece4Schristos   *  therefore flushing is limited by speed of oldest job. */
95*3117ece4Schristos size_t ZSTDMT_toFlushNow(ZSTDMT_CCtx* mtctx);
96*3117ece4Schristos 
97*3117ece4Schristos /*! ZSTDMT_updateCParams_whileCompressing() :
98*3117ece4Schristos  *  Updates only a selected set of compression parameters, to remain compatible with current frame.
99*3117ece4Schristos  *  New parameters will be applied to next compression job. */
100*3117ece4Schristos void ZSTDMT_updateCParams_whileCompressing(ZSTDMT_CCtx* mtctx, const ZSTD_CCtx_params* cctxParams);
101*3117ece4Schristos 
102*3117ece4Schristos /*! ZSTDMT_getFrameProgression():
103*3117ece4Schristos  *  tells how much data has been consumed (input) and produced (output) for current frame.
104*3117ece4Schristos  *  able to count progression inside worker threads.
105*3117ece4Schristos  */
106*3117ece4Schristos ZSTD_frameProgression ZSTDMT_getFrameProgression(ZSTDMT_CCtx* mtctx);
107*3117ece4Schristos 
108*3117ece4Schristos 
109*3117ece4Schristos #if defined (__cplusplus)
110*3117ece4Schristos }
111*3117ece4Schristos #endif
112*3117ece4Schristos 
113*3117ece4Schristos #endif   /* ZSTDMT_COMPRESS_H */
114