mirror of
				https://github.com/facebook/zstd.git
				synced 2025-10-31 08:37:43 +02:00 
			
		
		
		
	makes it possible to compile libzstd in single-thread mode without zstdmt_compress.c (#819)
This commit is contained in:
		
							
								
								
									
										1
									
								
								NEWS
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								NEWS
									
									
									
									
									
								
							| @@ -3,6 +3,7 @@ license : changed /examples license to BSD + GPLv2 | ||||
| license : fix a few header files to reflect new license (#825) | ||||
| fix : 32-bits build can now decode large offsets (levels 21+) | ||||
| fix : a rare compression bug when compression generates very large distances (only possible at --ultra -22) | ||||
| build: fix : no-multithread variant compiles without pool.c dependency, reported by Mitchell Blank Jr (@mitchblank) (#819) | ||||
| build: better compatibility with reproducible builds, by Bernhard M. Wiedemann (@bmwiedemann) (#818) | ||||
|  | ||||
| v1.3.1 | ||||
|   | ||||
| @@ -9,7 +9,7 @@ dependencies: | ||||
| test: | ||||
|   override: | ||||
|     - ? | | ||||
|         if [[ "$CIRCLE_NODE_INDEX" == "0" ]]                                    ; then cc -v; make all   && make clean; fi && | ||||
|         if [[ "$CIRCLE_NODE_INDEX" == "0" ]]                                    ; then cc -v; make all   && make clean && make -C lib libzstd-nomt && make clean; fi && | ||||
|         if [[ "$CIRCLE_NODE_TOTAL" < "2" ]] || [[ "$CIRCLE_NODE_INDEX" == "1" ]]; then make gnu90build   && make clean; fi | ||||
|       : | ||||
|         parallel: true | ||||
|   | ||||
							
								
								
									
										1
									
								
								lib/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								lib/.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -1,2 +1,3 @@ | ||||
| # make install artefact | ||||
| libzstd.pc | ||||
| libzstd-nomt | ||||
|   | ||||
							
								
								
									
										11
									
								
								lib/Makefile
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								lib/Makefile
									
									
									
									
									
								
							| @@ -101,10 +101,19 @@ lib-release lib-release-mt: DEBUGFLAGS := | ||||
| lib-release: lib | ||||
| lib-release-mt: lib-mt | ||||
|  | ||||
| # Special case : building library in single-thread mode _and_ without zstdmt_compress.c | ||||
| ZSTDMT_FILES = compress/zstdmt_compress.c | ||||
| ZSTD_NOMT_FILES = $(filter-out $(ZSTDMT_FILES),$(ZSTD_FILES)) | ||||
| libzstd-nomt: LDFLAGS += -shared -fPIC -fvisibility=hidden | ||||
| libzstd-nomt: $(ZSTD_NOMT_FILES) | ||||
| 	@echo compiling single-thread dynamic library $(LIBVER) | ||||
| 	@echo files : $(ZSTD_NOMT_FILES) | ||||
| 	@$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@ | ||||
|  | ||||
| clean: | ||||
| 	@$(RM) -r *.dSYM   # Mac OS-X specific | ||||
| 	@$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc | ||||
| 	@$(RM) dll/libzstd.dll dll/libzstd.lib | ||||
| 	@$(RM) dll/libzstd.dll dll/libzstd.lib libzstd-nomt* | ||||
| 	@$(RM) common/*.o compress/*.o decompress/*.o dictBuilder/*.o legacy/*.o deprecated/*.o | ||||
| 	@echo Cleaning library completed | ||||
|  | ||||
|   | ||||
| @@ -112,23 +112,37 @@ size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx) | ||||
|     cctx->workSpace = NULL; | ||||
|     ZSTD_freeCDict(cctx->cdictLocal); | ||||
|     cctx->cdictLocal = NULL; | ||||
| #ifdef ZSTD_MULTITHREAD | ||||
|     ZSTDMT_freeCCtx(cctx->mtctx); | ||||
|     cctx->mtctx = NULL; | ||||
| #endif | ||||
|     ZSTD_free(cctx, cctx->customMem); | ||||
|     return 0;   /* reserved as a potential error code in the future */ | ||||
| } | ||||
|  | ||||
|  | ||||
| static size_t ZSTD_sizeof_mtctx(const ZSTD_CCtx* cctx) | ||||
| { | ||||
| #ifdef ZSTD_MULTITHREAD | ||||
|     return ZSTDMT_sizeof_CCtx(cctx->mtctx); | ||||
| #else | ||||
|     (void) cctx; | ||||
|     return 0; | ||||
| #endif | ||||
| } | ||||
|  | ||||
|  | ||||
| size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx) | ||||
| { | ||||
|     if (cctx==NULL) return 0;   /* support sizeof on NULL */ | ||||
|     DEBUGLOG(5, "sizeof(*cctx) : %u", (U32)sizeof(*cctx)); | ||||
|     DEBUGLOG(5, "workSpaceSize : %u", (U32)cctx->workSpaceSize); | ||||
|     DEBUGLOG(5, "streaming buffers : %u", (U32)(cctx->outBuffSize + cctx->inBuffSize)); | ||||
|     DEBUGLOG(5, "inner MTCTX : %u", (U32)ZSTDMT_sizeof_CCtx(cctx->mtctx)); | ||||
|     DEBUGLOG(5, "inner MTCTX : %u", (U32)ZSTD_sizeof_mtctx(cctx)); | ||||
|     return sizeof(*cctx) + cctx->workSpaceSize | ||||
|            + ZSTD_sizeof_CDict(cctx->cdictLocal) | ||||
|            + cctx->outBuffSize + cctx->inBuffSize | ||||
|            + ZSTDMT_sizeof_CCtx(cctx->mtctx); | ||||
|            + ZSTD_sizeof_mtctx(cctx); | ||||
| } | ||||
|  | ||||
| size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs) | ||||
| @@ -238,10 +252,6 @@ static ZSTD_CCtx_params ZSTD_assignParamsToCCtxParams( | ||||
|         return ERROR(parameter_outOfBound);  \ | ||||
| }   } | ||||
|  | ||||
| size_t ZSTDMT_CCtxParam_setMTCtxParameter( | ||||
|     ZSTD_CCtx_params* params, ZSTDMT_parameter parameter, unsigned value); | ||||
| size_t ZSTDMT_initializeCCtxParameters(ZSTD_CCtx_params* params, unsigned nbThreads); | ||||
|  | ||||
| size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned value) | ||||
| { | ||||
|     if (cctx->streamStage != zcss_init) return ERROR(stage_wrong); | ||||
| @@ -379,16 +389,25 @@ size_t ZSTD_CCtxParam_setParameter( | ||||
|         if (value == 0) return 0; | ||||
| #ifndef ZSTD_MULTITHREAD | ||||
|         if (value > 1) return ERROR(parameter_unsupported); | ||||
| #endif | ||||
| #else | ||||
|         return ZSTDMT_initializeCCtxParameters(params, value); | ||||
| #endif | ||||
|  | ||||
|     case ZSTD_p_jobSize : | ||||
| #ifndef ZSTD_MULTITHREAD | ||||
|         return ERROR(parameter_unsupported); | ||||
| #else | ||||
|         if (params->nbThreads <= 1) return ERROR(parameter_unsupported); | ||||
|         return ZSTDMT_CCtxParam_setMTCtxParameter(params, ZSTDMT_p_sectionSize, value); | ||||
| #endif | ||||
|  | ||||
|     case ZSTD_p_overlapSizeLog : | ||||
| #ifndef ZSTD_MULTITHREAD | ||||
|         return ERROR(parameter_unsupported); | ||||
| #else | ||||
|         if (params->nbThreads <= 1) return ERROR(parameter_unsupported); | ||||
|         return ZSTDMT_CCtxParam_setMTCtxParameter(params, ZSTDMT_p_overlapSectionLog, value); | ||||
| #endif | ||||
|  | ||||
|     default: return ERROR(parameter_unsupported); | ||||
|     } | ||||
| @@ -2531,16 +2550,6 @@ size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuf | ||||
|     return ZSTD_compressStream_generic(zcs, output, input, ZSTD_e_continue); | ||||
| } | ||||
|  | ||||
| /*! ZSTDMT_initCStream_internal() : | ||||
|  *  Private use only. Init streaming operation. | ||||
|  *  expects params to be valid. | ||||
|  *  must receive dict, or cdict, or none, but not both. | ||||
|  *  @return : 0, or an error code */ | ||||
| size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx* zcs, | ||||
|                     const void* dict, size_t dictSize, ZSTD_dictMode_e dictMode, | ||||
|                     const ZSTD_CDict* cdict, | ||||
|                     ZSTD_CCtx_params params, unsigned long long pledgedSrcSize); | ||||
|  | ||||
|  | ||||
| size_t ZSTD_compress_generic (ZSTD_CCtx* cctx, | ||||
|                               ZSTD_outBuffer* output, | ||||
|   | ||||
| @@ -16,7 +16,9 @@ | ||||
| *  Dependencies | ||||
| ***************************************/ | ||||
| #include "zstd_internal.h" | ||||
| #include "zstdmt_compress.h" | ||||
| #ifdef ZSTD_MULTITHREAD | ||||
| #  include "zstdmt_compress.h" | ||||
| #endif | ||||
|  | ||||
| #if defined (__cplusplus) | ||||
| extern "C" { | ||||
| @@ -90,7 +92,9 @@ struct ZSTD_CCtx_s { | ||||
|     ZSTD_prefixDict prefixDict;   /* single-usage dictionary */ | ||||
|  | ||||
|     /* Multi-threading */ | ||||
| #ifdef ZSTD_MULTITHREAD | ||||
|     ZSTDMT_CCtx* mtctx; | ||||
| #endif | ||||
| }; | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -108,6 +108,22 @@ ZSTDLIB_API size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx, | ||||
|                                                 ZSTD_EndDirective endOp); | ||||
|  | ||||
|  | ||||
| /* ===   Private definitions; never ever use directly  === */ | ||||
|  | ||||
| size_t ZSTDMT_CCtxParam_setMTCtxParameter(ZSTD_CCtx_params* params, ZSTDMT_parameter parameter, unsigned value); | ||||
|  | ||||
| size_t ZSTDMT_initializeCCtxParameters(ZSTD_CCtx_params* params, unsigned nbThreads); | ||||
|  | ||||
| /*! ZSTDMT_initCStream_internal() : | ||||
|  *  Private use only. Init streaming operation. | ||||
|  *  expects params to be valid. | ||||
|  *  must receive dict, or cdict, or none, but not both. | ||||
|  *  @return : 0, or an error code */ | ||||
| size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx* zcs, | ||||
|                     const void* dict, size_t dictSize, ZSTD_dictMode_e dictMode, | ||||
|                     const ZSTD_CDict* cdict, | ||||
|                     ZSTD_CCtx_params params, unsigned long long pledgedSrcSize); | ||||
|  | ||||
|  | ||||
| #if defined (__cplusplus) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user