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