diff --git a/C/zstdmt/zstd-mt.h b/C/zstdmt/zstd-mt.h index 13593f38..6f51bb32 100644 --- a/C/zstdmt/zstd-mt.h +++ b/C/zstdmt/zstd-mt.h @@ -15,8 +15,8 @@ * Defines ****************************************/ -#ifndef ZSTDMT_H -#define ZSTDMT_H +#ifndef ZSTDCB_H +#define ZSTDCB_H #if defined (__cplusplus) extern "C" { @@ -24,41 +24,41 @@ extern "C" { #include /* size_t */ -#define ZSTDMT_THREAD_MAX 128 -#define ZSTDMT_LEVEL_MIN 1 -#define ZSTDMT_LEVEL_MAX 22 +#define ZSTDCB_THREAD_MAX 128 +#define ZSTDCB_LEVEL_MIN 1 +#define ZSTDCB_LEVEL_MAX 22 /* zstd magic values */ -#define ZSTDMT_MAGICNUMBER_V01 0x1EB52FFDU -#define ZSTDMT_MAGICNUMBER_MIN 0xFD2FB522U -#define ZSTDMT_MAGICNUMBER_MAX 0xFD2FB528U -#define ZSTDMT_MAGIC_SKIPPABLE 0x184D2A50U +#define ZSTDCB_MAGICNUMBER_V01 0x1EB52FFDU +#define ZSTDCB_MAGICNUMBER_MIN 0xFD2FB522U +#define ZSTDCB_MAGICNUMBER_MAX 0xFD2FB528U +#define ZSTDCB_MAGIC_SKIPPABLE 0x184D2A50U /* ************************************** * Error Handling ****************************************/ typedef enum { - ZSTDMT_error_no_error, - ZSTDMT_error_memory_allocation, - ZSTDMT_error_init_missing, - ZSTDMT_error_read_fail, - ZSTDMT_error_write_fail, - ZSTDMT_error_data_error, - ZSTDMT_error_frame_compress, - ZSTDMT_error_frame_decompress, - ZSTDMT_error_compressionParameter_unsupported, - ZSTDMT_error_compression_library, - ZSTDMT_error_canceled, - ZSTDMT_error_maxCode -} ZSTDMT_ErrorCode; + ZSTDCB_error_no_error, + ZSTDCB_error_memory_allocation, + ZSTDCB_error_init_missing, + ZSTDCB_error_read_fail, + ZSTDCB_error_write_fail, + ZSTDCB_error_data_error, + ZSTDCB_error_frame_compress, + ZSTDCB_error_frame_decompress, + ZSTDCB_error_compressionParameter_unsupported, + ZSTDCB_error_compression_library, + ZSTDCB_error_canceled, + ZSTDCB_error_maxCode +} ZSTDCB_ErrorCode; extern size_t zstdmt_errcode; -#define ZSTDMT_PREFIX(name) ZSTDMT_error_##name -#define ZSTDMT_ERROR(name) ((size_t)-ZSTDMT_PREFIX(name)) -extern unsigned ZSTDMT_isError(size_t code); -extern const char* ZSTDMT_getErrorString(size_t code); +#define ZSTDCB_PREFIX(name) ZSTDCB_error_##name +#define ZSTDCB_ERROR(name) ((size_t)-ZSTDCB_PREFIX(name)) +extern unsigned ZSTDCB_isError(size_t code); +extern const char* ZSTDCB_getErrorString(size_t code); /* ************************************** * Structures @@ -68,7 +68,7 @@ typedef struct { void *buf; /* ptr to data */ size_t size; /* current filled in buf */ size_t allocated; /* length of buf */ -} ZSTDMT_Buffer; +} ZSTDCB_Buffer; /** * reading and writing functions @@ -82,54 +82,54 @@ typedef struct { * -2 = user abort * -3 = memory */ -typedef int (fn_read) (void *args, ZSTDMT_Buffer * in); -typedef int (fn_write) (void *args, ZSTDMT_Buffer * out); +typedef int (fn_read) (void *args, ZSTDCB_Buffer * in); +typedef int (fn_write) (void *args, ZSTDCB_Buffer * out); typedef struct { fn_read *fn_read; void *arg_read; fn_write *fn_write; void *arg_write; -} ZSTDMT_RdWr_t; +} ZSTDCB_RdWr_t; /* ************************************** * Compression ****************************************/ -typedef struct ZSTDMT_CCtx_s ZSTDMT_CCtx; +typedef struct ZSTDCB_CCtx_s ZSTDCB_CCtx; /** - * ZSTDMT_createCCtx() - allocate new compression context + * ZSTDCB_createCCtx() - allocate new compression context * * This function allocates and initializes an zstd commpression context. * The context can be used multiple times without the need for resetting * or re-initializing. * * @level: compression level, which should be used (1..22) - * @threads: number of threads, which should be used (1..ZSTDMT_THREAD_MAX) + * @threads: number of threads, which should be used (1..ZSTDCB_THREAD_MAX) * @inputsize: - if zero, becomes some optimal value for the level * - if nonzero, the given value is taken * @zstdmt_errcode: space for storing zstd errors (needed for thread safety) * @return: the context on success, zero on error */ -ZSTDMT_CCtx *ZSTDMT_createCCtx(int threads, int level, int inputsize); +ZSTDCB_CCtx *ZSTDCB_createCCtx(int threads, int level, int inputsize); /** - * ZSTDMT_compressDCtx() - threaded compression for zstd + * ZSTDCB_compressDCtx() - threaded compression for zstd * * This function will create valid zstd streams. The number of threads, * the input chunksize and the compression level are .... * - * @ctx: context, which needs to be created with ZSTDMT_createDCtx() + * @ctx: context, which needs to be created with ZSTDCB_createDCtx() * @rdwr: callback structure, which defines reding/writing functions * @return: zero on success, or error code */ -size_t ZSTDMT_compressCCtx(ZSTDMT_CCtx * ctx, ZSTDMT_RdWr_t * rdwr); +size_t ZSTDCB_compressCCtx(ZSTDCB_CCtx * ctx, ZSTDCB_RdWr_t * rdwr); /** - * ZSTDMT_GetFramesCCtx() - number of written frames - * ZSTDMT_GetInsizeCCtx() - read bytes of input - * ZSTDMT_GetOutsizeCCtx() - written bytes of output + * ZSTDCB_GetFramesCCtx() - number of written frames + * ZSTDCB_GetInsizeCCtx() - read bytes of input + * ZSTDCB_GetOutsizeCCtx() - written bytes of output * * These three functions will return some statistical data of the * compression context ctx. @@ -137,52 +137,52 @@ size_t ZSTDMT_compressCCtx(ZSTDMT_CCtx * ctx, ZSTDMT_RdWr_t * rdwr); * @ctx: context, which should be examined * @return: the request value, or zero on error */ -size_t ZSTDMT_GetFramesCCtx(ZSTDMT_CCtx * ctx); -size_t ZSTDMT_GetInsizeCCtx(ZSTDMT_CCtx * ctx); -size_t ZSTDMT_GetOutsizeCCtx(ZSTDMT_CCtx * ctx); +size_t ZSTDCB_GetFramesCCtx(ZSTDCB_CCtx * ctx); +size_t ZSTDCB_GetInsizeCCtx(ZSTDCB_CCtx * ctx); +size_t ZSTDCB_GetOutsizeCCtx(ZSTDCB_CCtx * ctx); /** - * ZSTDMT_freeCCtx() - free compression context + * ZSTDCB_freeCCtx() - free compression context * * This function will free all allocated resources, which were allocated - * by ZSTDMT_createCCtx(). This function can not fail. + * by ZSTDCB_createCCtx(). This function can not fail. * * @ctx: context, which should be freed */ -void ZSTDMT_freeCCtx(ZSTDMT_CCtx * ctx); +void ZSTDCB_freeCCtx(ZSTDCB_CCtx * ctx); /* ************************************** * Decompression ****************************************/ -typedef struct ZSTDMT_DCtx_s ZSTDMT_DCtx; +typedef struct ZSTDCB_DCtx_s ZSTDCB_DCtx; /** * 1) allocate new cctx * - return cctx or zero on error * * @level - 1 .. 22 - * @threads - 1 .. ZSTDMT_THREAD_MAX - * @srclen - the max size of src for ZSTDMT_compressCCtx() + * @threads - 1 .. ZSTDCB_THREAD_MAX + * @srclen - the max size of src for ZSTDCB_compressCCtx() * @dstlen - the min size of dst */ -ZSTDMT_DCtx *ZSTDMT_createDCtx(int threads, int inputsize); +ZSTDCB_DCtx *ZSTDCB_createDCtx(int threads, int inputsize); /** - * ZSTDMT_decompressDCtx() - threaded decompression for zstd + * ZSTDCB_decompressDCtx() - threaded decompression for zstd * * This function will decompress valid zstd streams. * - * @ctx: context, which needs to be created with ZSTDMT_createDCtx() + * @ctx: context, which needs to be created with ZSTDCB_createDCtx() * @rdwr: callback structure, which defines reding/writing functions * @return: zero on success, or error code */ -size_t ZSTDMT_decompressDCtx(ZSTDMT_DCtx * ctx, ZSTDMT_RdWr_t * rdwr); +size_t ZSTDCB_decompressDCtx(ZSTDCB_DCtx * ctx, ZSTDCB_RdWr_t * rdwr); /** - * ZSTDMT_GetFramesDCtx() - number of read frames - * ZSTDMT_GetInsizeDCtx() - read bytes of input - * ZSTDMT_GetOutsizeDCtx() - written bytes of output + * ZSTDCB_GetFramesDCtx() - number of read frames + * ZSTDCB_GetInsizeDCtx() - read bytes of input + * ZSTDCB_GetOutsizeDCtx() - written bytes of output * * These three functions will return some statistical data of the * decompression context ctx. @@ -190,21 +190,21 @@ size_t ZSTDMT_decompressDCtx(ZSTDMT_DCtx * ctx, ZSTDMT_RdWr_t * rdwr); * @ctx: context, which should be examined * @return: the request value, or zero on error */ -size_t ZSTDMT_GetFramesDCtx(ZSTDMT_DCtx * ctx); -size_t ZSTDMT_GetInsizeDCtx(ZSTDMT_DCtx * ctx); -size_t ZSTDMT_GetOutsizeDCtx(ZSTDMT_DCtx * ctx); +size_t ZSTDCB_GetFramesDCtx(ZSTDCB_DCtx * ctx); +size_t ZSTDCB_GetInsizeDCtx(ZSTDCB_DCtx * ctx); +size_t ZSTDCB_GetOutsizeDCtx(ZSTDCB_DCtx * ctx); /** - * ZSTDMT_freeDCtx() - free decompression context + * ZSTDCB_freeDCtx() - free decompression context * * This function will free all allocated resources, which were allocated - * by ZSTDMT_createDCtx(). This function can not fail. + * by ZSTDCB_createDCtx(). This function can not fail. * * @ctx: context, which should be freed */ -void ZSTDMT_freeDCtx(ZSTDMT_DCtx * ctx); +void ZSTDCB_freeDCtx(ZSTDCB_DCtx * ctx); #if defined (__cplusplus) } #endif -#endif /* ZSTDMT_H */ +#endif /* ZSTDCB_H */ diff --git a/C/zstdmt/zstd-mt_common.c b/C/zstdmt/zstd-mt_common.c index 294a5de8..373c99a8 100644 --- a/C/zstdmt/zstd-mt_common.c +++ b/C/zstdmt/zstd-mt_common.c @@ -19,43 +19,43 @@ size_t zstdmt_errcode; /** - * ZSTDMT_isError() - tells if a return value is an error code + * ZSTDCB_isError() - tells if a return value is an error code */ -unsigned ZSTDMT_isError(size_t code) +unsigned ZSTDCB_isError(size_t code) { - return (code > ZSTDMT_ERROR(maxCode)); + return (code > ZSTDCB_ERROR(maxCode)); } /** * LZ4MT_getErrorString() - give error code string from function result */ -const char *ZSTDMT_getErrorString(size_t code) +const char *ZSTDCB_getErrorString(size_t code) { static const char *noErrorCode = "Unspecified zstmt error code"; if (ZSTD_isError(zstdmt_errcode)) return ZSTD_getErrorName(zstdmt_errcode); - switch ((ZSTDMT_ErrorCode) (0 - code)) { - case ZSTDMT_PREFIX(no_error): + switch ((ZSTDCB_ErrorCode) (0 - code)) { + case ZSTDCB_PREFIX(no_error): return "No error detected"; - case ZSTDMT_PREFIX(memory_allocation): + case ZSTDCB_PREFIX(memory_allocation): return "Allocation error : not enough memory"; - case ZSTDMT_PREFIX(read_fail): + case ZSTDCB_PREFIX(read_fail): return "Read failure"; - case ZSTDMT_PREFIX(write_fail): + case ZSTDCB_PREFIX(write_fail): return "Write failure"; - case ZSTDMT_PREFIX(data_error): + case ZSTDCB_PREFIX(data_error): return "Malformed input"; - case ZSTDMT_PREFIX(frame_compress): + case ZSTDCB_PREFIX(frame_compress): return "Could not compress frame at once"; - case ZSTDMT_PREFIX(frame_decompress): + case ZSTDCB_PREFIX(frame_decompress): return "Could not decompress frame at once"; - case ZSTDMT_PREFIX(compressionParameter_unsupported): + case ZSTDCB_PREFIX(compressionParameter_unsupported): return "Compression parameter is out of bound"; - case ZSTDMT_PREFIX(compression_library): + case ZSTDCB_PREFIX(compression_library): return "Compression library reports failure"; - case ZSTDMT_PREFIX(maxCode): + case ZSTDCB_PREFIX(maxCode): default: return noErrorCode; } diff --git a/C/zstdmt/zstd-mt_compress.c b/C/zstdmt/zstd-mt_compress.c index fe9a1d9e..d002c3c4 100644 --- a/C/zstdmt/zstd-mt_compress.c +++ b/C/zstdmt/zstd-mt_compress.c @@ -36,23 +36,23 @@ /* worker for compression */ typedef struct { - ZSTDMT_CCtx *ctx; + ZSTDCB_CCtx *ctx; pthread_t pthread; } cwork_t; struct writelist; struct writelist { size_t frame; - ZSTDMT_Buffer out; + ZSTDCB_Buffer out; struct list_head node; }; -struct ZSTDMT_CCtx_s { +struct ZSTDCB_CCtx_s { - /* level: 1..ZSTDMT_LEVEL_MAX */ + /* level: 1..ZSTDCB_LEVEL_MAX */ int level; - /* threads: 1..ZSTDMT_THREAD_MAX */ + /* threads: 1..ZSTDCB_THREAD_MAX */ int threads; /* buffersize for reading input */ @@ -91,43 +91,39 @@ struct ZSTDMT_CCtx_s { * Compression ****************************************/ -ZSTDMT_CCtx *ZSTDMT_createCCtx(int threads, int level, int inputsize) +ZSTDCB_CCtx *ZSTDCB_createCCtx(int threads, int level, int inputsize) { - ZSTDMT_CCtx *ctx; + ZSTDCB_CCtx *ctx; int t; /* allocate ctx */ - ctx = (ZSTDMT_CCtx *) malloc(sizeof(ZSTDMT_CCtx)); + ctx = (ZSTDCB_CCtx *) malloc(sizeof(ZSTDCB_CCtx)); if (!ctx) return 0; /* check threads value */ - if (threads < 1 || threads > ZSTDMT_THREAD_MAX) + if (threads < 1 || threads > ZSTDCB_THREAD_MAX) goto err_ctx; /* check level */ - if (level < ZSTDMT_LEVEL_MIN || level > ZSTDMT_LEVEL_MAX) + if (level < ZSTDCB_LEVEL_MIN || level > ZSTDCB_LEVEL_MAX) goto err_ctx; + + + /* calculate chunksize for one thread */ if (inputsize) ctx->inputsize = inputsize; else { -#if 1 const int windowLog[] = { - 0, 19, 19, 20, 20, 20, 21, 21, - 21, 21, 21, 22, 22, 22, 22, 22, - 23, 23, 23, 23, 23, 25, 26, 27 + 19, 19, 20, 20, 20, /* 1 - 5 */ + 21, 21, 21, 21, 21, /* 6 - 10 */ + 22, 22, 22, 22, 22, /* 11 - 15 */ + 23, 23, 23, 23, 25, /* 16 - 20 */ + 26, 27 }; - ctx->inputsize = 1 << (windowLog[level] + 1); -#else - const int mb[] = { - 0, 1, 1, 1, 2, 2, 2, - 3, 3, 3, 4, 4, 4, 5, - 5, 5, 5, 5, 5, 5, 5 - }; - ctx->inputsize = 1024 * 1024 * mb[level]; -#endif + ctx->inputsize = 1 << (windowLog[level - 1] + 1); } /* setup ctx */ @@ -165,20 +161,20 @@ static size_t mt_error(int rv) { switch (rv) { case -1: - return ZSTDMT_ERROR(read_fail); + return ZSTDCB_ERROR(read_fail); case -2: - return ZSTDMT_ERROR(canceled); + return ZSTDCB_ERROR(canceled); case -3: - return ZSTDMT_ERROR(memory_allocation); + return ZSTDCB_ERROR(memory_allocation); } - return ZSTDMT_ERROR(read_fail); + return ZSTDCB_ERROR(read_fail); } /** * pt_write - queue for compressed output */ -static size_t pt_write(ZSTDMT_CCtx * ctx, struct writelist *wl) +static size_t pt_write(ZSTDCB_CCtx * ctx, struct writelist *wl) { struct list_head *entry; int rv; @@ -212,20 +208,20 @@ static size_t pt_write(ZSTDMT_CCtx * ctx, struct writelist *wl) static void *pt_compress(void *arg) { cwork_t *w = (cwork_t *) arg; - ZSTDMT_CCtx *ctx = w->ctx; + ZSTDCB_CCtx *ctx = w->ctx; struct writelist *wl; size_t result; - ZSTDMT_Buffer in; + ZSTDCB_Buffer in; /* inbuf is constant */ in.size = ctx->inputsize; in.buf = malloc(in.size); if (!in.buf) - return (void *)ZSTDMT_ERROR(memory_allocation); + return (void *)ZSTDCB_ERROR(memory_allocation); for (;;) { struct list_head *entry; - ZSTDMT_Buffer *out; + ZSTDCB_Buffer *out; int rv; /* allocate space for new output */ @@ -243,14 +239,14 @@ static void *pt_compress(void *arg) if (!wl) { pthread_mutex_unlock(&ctx->write_mutex); free(in.buf); - return (void *)ZSTDMT_ERROR(memory_allocation); + return (void *)ZSTDCB_ERROR(memory_allocation); } wl->out.size = ZSTD_compressBound(ctx->inputsize) + 12;; wl->out.buf = malloc(wl->out.size); if (!wl->out.buf) { pthread_mutex_unlock(&ctx->write_mutex); free(in.buf); - return (void *)ZSTDMT_ERROR(memory_allocation); + return (void *)ZSTDCB_ERROR(memory_allocation); } list_add(&wl->node, &ctx->writelist_busy); } @@ -290,7 +286,7 @@ static void *pt_compress(void *arg) in.size, ctx->level); if (ZSTD_isError(result)) { zstdmt_errcode = result; - result = ZSTDMT_ERROR(compression_library); + result = ZSTDCB_ERROR(compression_library); goto error; } } @@ -299,7 +295,7 @@ static void *pt_compress(void *arg) { unsigned char *outbuf = out->buf; - MEM_writeLE32(outbuf + 0, ZSTDMT_MAGIC_SKIPPABLE); + MEM_writeLE32(outbuf + 0, ZSTDCB_MAGIC_SKIPPABLE); MEM_writeLE32(outbuf + 4, 4); MEM_writeLE32(outbuf + 8, (U32) result); out->size = result + 12; @@ -309,7 +305,7 @@ static void *pt_compress(void *arg) pthread_mutex_lock(&ctx->write_mutex); result = pt_write(ctx, wl); pthread_mutex_unlock(&ctx->write_mutex); - if (ZSTDMT_isError(result)) + if (ZSTDCB_isError(result)) goto error; } @@ -323,13 +319,13 @@ static void *pt_compress(void *arg) } /* compress data, until input ends */ -size_t ZSTDMT_compressCCtx(ZSTDMT_CCtx * ctx, ZSTDMT_RdWr_t * rdwr) +size_t ZSTDCB_compressCCtx(ZSTDCB_CCtx * ctx, ZSTDCB_RdWr_t * rdwr) { int t; void *retval_of_thread = 0; if (!ctx) - return ZSTDMT_ERROR(init_missing); + return ZSTDCB_ERROR(init_missing); /* setup reading and writing functions */ ctx->fn_read = rdwr->fn_read; @@ -396,37 +392,37 @@ size_t ZSTDMT_compressCCtx(ZSTDMT_CCtx * ctx, ZSTDMT_RdWr_t * rdwr) } /* returns current uncompressed data size */ -size_t ZSTDMT_GetInsizeCCtx(ZSTDMT_CCtx * ctx) +size_t ZSTDCB_GetInsizeCCtx(ZSTDCB_CCtx * ctx) { if (!ctx) - return ZSTDMT_ERROR(init_missing); + return ZSTDCB_ERROR(init_missing); /* no mutex needed here */ return ctx->insize; } /* returns the current compressed data size */ -size_t ZSTDMT_GetOutsizeCCtx(ZSTDMT_CCtx * ctx) +size_t ZSTDCB_GetOutsizeCCtx(ZSTDCB_CCtx * ctx) { if (!ctx) - return ZSTDMT_ERROR(init_missing); + return ZSTDCB_ERROR(init_missing); /* no mutex needed here */ return ctx->outsize; } /* returns the current compressed data frame count */ -size_t ZSTDMT_GetFramesCCtx(ZSTDMT_CCtx * ctx) +size_t ZSTDCB_GetFramesCCtx(ZSTDCB_CCtx * ctx) { if (!ctx) - return ZSTDMT_ERROR(init_missing); + return ZSTDCB_ERROR(init_missing); /* no mutex needed here */ return ctx->curframe; } /* free all allocated buffers and structures */ -void ZSTDMT_freeCCtx(ZSTDMT_CCtx * ctx) +void ZSTDCB_freeCCtx(ZSTDCB_CCtx * ctx) { if (!ctx) return; diff --git a/C/zstdmt/zstd-mt_decompress.c b/C/zstdmt/zstd-mt_decompress.c index 59a11382..1f0522e6 100644 --- a/C/zstdmt/zstd-mt_decompress.c +++ b/C/zstdmt/zstd-mt_decompress.c @@ -45,22 +45,22 @@ extern size_t zstdmt_errcode; /* worker for compression */ typedef struct { - ZSTDMT_DCtx *ctx; + ZSTDCB_DCtx *ctx; pthread_t pthread; - ZSTDMT_Buffer in; + ZSTDCB_Buffer in; ZSTD_DStream *dctx; } cwork_t; struct writelist; struct writelist { size_t frame; - ZSTDMT_Buffer out; + ZSTDCB_Buffer out; struct list_head node; }; -struct ZSTDMT_DCtx_s { +struct ZSTDCB_DCtx_s { - /* threads: 1..ZSTDMT_THREAD_MAX */ + /* threads: 1..ZSTDCB_THREAD_MAX */ int threads; int threadswanted; @@ -102,17 +102,17 @@ struct ZSTDMT_DCtx_s { * Decompression ****************************************/ -ZSTDMT_DCtx *ZSTDMT_createDCtx(int threads, int inputsize) +ZSTDCB_DCtx *ZSTDCB_createDCtx(int threads, int inputsize) { - ZSTDMT_DCtx *ctx; + ZSTDCB_DCtx *ctx; /* allocate ctx */ - ctx = (ZSTDMT_DCtx *) malloc(sizeof(ZSTDMT_DCtx)); + ctx = (ZSTDCB_DCtx *) malloc(sizeof(ZSTDCB_DCtx)); if (!ctx) return 0; /* check threads value */ - if (threads < 1 || threads > ZSTDMT_THREAD_MAX) + if (threads < 1 || threads > ZSTDCB_THREAD_MAX) return 0; /* setup ctx */ @@ -144,10 +144,10 @@ ZSTDMT_DCtx *ZSTDMT_createDCtx(int threads, int inputsize) static int IsZstd_Magic(unsigned char *buf) { U32 magic = MEM_readLE32(buf); - if (magic == ZSTDMT_MAGICNUMBER_V01) + if (magic == ZSTDCB_MAGICNUMBER_V01) return 1; - return (magic >= ZSTDMT_MAGICNUMBER_MIN - && magic <= ZSTDMT_MAGICNUMBER_MAX); + return (magic >= ZSTDCB_MAGICNUMBER_MIN + && magic <= ZSTDCB_MAGICNUMBER_MAX); } /** @@ -155,7 +155,7 @@ static int IsZstd_Magic(unsigned char *buf) */ static int IsZstd_Skippable(unsigned char *buf) { - return (MEM_readLE32(buf) == ZSTDMT_MAGIC_SKIPPABLE); + return (MEM_readLE32(buf) == ZSTDCB_MAGIC_SKIPPABLE); } /** @@ -165,21 +165,21 @@ static size_t mt_error(int rv) { switch (rv) { case -1: - return ZSTDMT_ERROR(read_fail); + return ZSTDCB_ERROR(read_fail); case -2: - return ZSTDMT_ERROR(canceled); + return ZSTDCB_ERROR(canceled); case -3: - return ZSTDMT_ERROR(memory_allocation); + return ZSTDCB_ERROR(memory_allocation); } /* XXX, some catch all other errors */ - return ZSTDMT_ERROR(read_fail); + return ZSTDCB_ERROR(read_fail); } /** * pt_write - queue for decompressed output */ -static size_t pt_write(ZSTDMT_DCtx * ctx, struct writelist *wl) +static size_t pt_write(ZSTDCB_DCtx * ctx, struct writelist *wl) { struct list_head *entry; @@ -206,10 +206,10 @@ static size_t pt_write(ZSTDMT_DCtx * ctx, struct writelist *wl) /** * pt_read - read compressed input */ -static size_t pt_read(ZSTDMT_DCtx * ctx, ZSTDMT_Buffer * in, size_t * frame) +static size_t pt_read(ZSTDCB_DCtx * ctx, ZSTDCB_Buffer * in, size_t * frame) { unsigned char hdrbuf[12]; - ZSTDMT_Buffer hdr; + ZSTDCB_Buffer hdr; size_t toRead; int rv; @@ -359,36 +359,36 @@ static size_t pt_read(ZSTDMT_DCtx * ctx, ZSTDMT_Buffer * in, size_t * frame) error_data: pthread_mutex_unlock(&ctx->read_mutex); - return ZSTDMT_ERROR(data_error); + return ZSTDCB_ERROR(data_error); error_read: pthread_mutex_unlock(&ctx->read_mutex); - return ZSTDMT_ERROR(read_fail); + return ZSTDCB_ERROR(read_fail); error_nomem: pthread_mutex_unlock(&ctx->read_mutex); - return ZSTDMT_ERROR(memory_allocation); + return ZSTDCB_ERROR(memory_allocation); } static void *pt_decompress(void *arg) { cwork_t *w = (cwork_t *) arg; - ZSTDMT_Buffer *in = &w->in; - ZSTDMT_DCtx *ctx = w->ctx; + ZSTDCB_Buffer *in = &w->in; + ZSTDCB_DCtx *ctx = w->ctx; struct writelist *wl; size_t result = 0; - ZSTDMT_Buffer collect; + ZSTDCB_Buffer collect; /* init dstream stream */ result = ZSTD_initDStream(w->dctx); if (ZSTD_isError(result)) { zstdmt_errcode = result; - return (void *)ZSTDMT_ERROR(compression_library); + return (void *)ZSTDCB_ERROR(compression_library); } collect.buf = 0; collect.size = 0; collect.allocated = 0; for (;;) { - ZSTDMT_Buffer *out; + ZSTDCB_Buffer *out; ZSTD_inBuffer zIn; ZSTD_outBuffer zOut; @@ -405,14 +405,14 @@ static void *pt_decompress(void *arg) wl = (struct writelist *) malloc(sizeof(struct writelist)); if (!wl) { - result = ZSTDMT_ERROR(memory_allocation); + result = ZSTDCB_ERROR(memory_allocation); goto error_unlock; } out = &wl->out; out->size = ctx->outputsize; out->buf = malloc(out->size); if (!out->buf) { - result = ZSTDMT_ERROR(memory_allocation); + result = ZSTDCB_ERROR(memory_allocation); goto error_unlock; } out->allocated = out->size; @@ -428,14 +428,14 @@ static void *pt_decompress(void *arg) result = ZSTD_resetDStream(w->dctx); if (ZSTD_isError(result)) { zstdmt_errcode = result; - return (void *)ZSTDMT_ERROR(compression_library); + return (void *)ZSTDCB_ERROR(compression_library); } /* zero should not happen here! */ result = pt_read(ctx, in, &wl->frame); if (in->size == 0) break; - if (ZSTDMT_isError(result)) { + if (ZSTDCB_isError(result)) { goto error_lock; } @@ -468,7 +468,7 @@ static void *pt_decompress(void *arg) bnew = malloc(collect.size + zOut.pos); if (!bnew) { result = - ZSTDMT_ERROR + ZSTDCB_ERROR (memory_allocation); goto error_lock; } @@ -489,7 +489,7 @@ static void *pt_decompress(void *arg) /* write result */ pthread_mutex_lock(&ctx->write_mutex); result = pt_write(ctx, wl); - if (ZSTDMT_isError(result)) + if (ZSTDCB_isError(result)) goto error_unlock; pthread_mutex_unlock(&ctx->write_mutex); /* will read next input */ @@ -514,7 +514,7 @@ static void *pt_decompress(void *arg) out->buf = realloc(out->buf, out->size); if (!out->buf) { result = - ZSTDMT_ERROR(memory_allocation); + ZSTDCB_ERROR(memory_allocation); goto error_lock; } out->allocated = out->size; @@ -536,7 +536,7 @@ static void *pt_decompress(void *arg) error_clib: zstdmt_errcode = result; - result = ZSTDMT_ERROR(compression_library); + result = ZSTDCB_ERROR(compression_library); /* fall through */ error_lock: pthread_mutex_lock(&ctx->write_mutex); @@ -551,12 +551,12 @@ static void *pt_decompress(void *arg) /* single threaded */ static size_t st_decompress(void *arg) { - ZSTDMT_DCtx *ctx = (ZSTDMT_DCtx *) arg; + ZSTDCB_DCtx *ctx = (ZSTDCB_DCtx *) arg; cwork_t *w = &ctx->cwork[0]; - ZSTDMT_Buffer In, Out; - ZSTDMT_Buffer *in = &In; - ZSTDMT_Buffer *out = &Out; - ZSTDMT_Buffer *magic = &w->in; + ZSTDCB_Buffer In, Out; + ZSTDCB_Buffer *in = &In; + ZSTDCB_Buffer *out = &Out; + ZSTDCB_Buffer *magic = &w->in; size_t result; int rv; @@ -567,14 +567,14 @@ static size_t st_decompress(void *arg) result = ZSTD_initDStream(w->dctx); if (ZSTD_isError(result)) { zstdmt_errcode = result; - return ZSTDMT_ERROR(compression_library); + return ZSTDCB_ERROR(compression_library); } /* allocate space for input buffer */ in->size = ZSTD_DStreamInSize(); in->buf = malloc(in->size); if (!in->buf) - return ZSTDMT_ERROR(memory_allocation); + return ZSTDCB_ERROR(memory_allocation); in->allocated = in->size; /* allocate space for output buffer */ @@ -582,7 +582,7 @@ static size_t st_decompress(void *arg) out->buf = malloc(out->size); if (!out->buf) { free(in->buf); - return ZSTDMT_ERROR(memory_allocation); + return ZSTDCB_ERROR(memory_allocation); } out->allocated = out->size; @@ -627,7 +627,7 @@ static size_t st_decompress(void *arg) goto error_clib; if (zOut.pos) { - ZSTDMT_Buffer wb; + ZSTDCB_Buffer wb; wb.size = zOut.pos; wb.buf = zOut.dst; rv = ctx->fn_write(ctx->arg_write, &wb); @@ -672,7 +672,7 @@ static size_t st_decompress(void *arg) error_clib: zstdmt_errcode = result; - result = ZSTDMT_ERROR(compression_library); + result = ZSTDCB_ERROR(compression_library); /* fall through */ error: /* return with error */ @@ -690,17 +690,17 @@ static size_t st_decompress(void *arg) #define TYPE_SINGLE_THREAD 1 #define TYPE_MULTI_THREAD 2 -size_t ZSTDMT_decompressDCtx(ZSTDMT_DCtx * ctx, ZSTDMT_RdWr_t * rdwr) +size_t ZSTDCB_decompressDCtx(ZSTDCB_DCtx * ctx, ZSTDCB_RdWr_t * rdwr) { unsigned char buf[16]; - ZSTDMT_Buffer In; - ZSTDMT_Buffer *in = &In; + ZSTDCB_Buffer In; + ZSTDCB_Buffer *in = &In; cwork_t *w; int t, rv, type = TYPE_UNKNOWN; void *retval_of_thread = 0; if (!ctx) - return ZSTDMT_ERROR(compressionParameter_unsupported); + return ZSTDCB_ERROR(compressionParameter_unsupported); /* init reading and writing functions */ ctx->fn_read = rdwr->fn_read; @@ -711,13 +711,13 @@ size_t ZSTDMT_decompressDCtx(ZSTDMT_DCtx * ctx, ZSTDMT_RdWr_t * rdwr) /** * possible valid magic's for us, we need 16 bytes, for checking * - * 1) ZSTDMT_MAGIC @0 -> ST Stream - * 2) ZSTDMT_MAGIC @0 + MAGIC_SKIPPABLE @9 -> MT Stream else ST - * 3) MAGIC_SKIPPABLE @0 + ZSTDMT_MAGIC @12 -> MT Stream + * 1) ZSTDCB_MAGIC @0 -> ST Stream + * 2) ZSTDCB_MAGIC @0 + MAGIC_SKIPPABLE @9 -> MT Stream else ST + * 3) MAGIC_SKIPPABLE @0 + ZSTDCB_MAGIC @12 -> MT Stream * 4) all other: not valid! */ - /* check for ZSTDMT_MAGIC_SKIPPABLE */ + /* check for ZSTDCB_MAGIC_SKIPPABLE */ in->buf = buf; in->size = 16; rv = ctx->fn_read(ctx->arg_read, in); @@ -727,7 +727,7 @@ size_t ZSTDMT_decompressDCtx(ZSTDMT_DCtx * ctx, ZSTDMT_RdWr_t * rdwr) /* must be single threaded standard zstd, when smaller 16 bytes */ if (in->size < 16) { if (!IsZstd_Magic(buf)) - return ZSTDMT_ERROR(data_error); + return ZSTDCB_ERROR(data_error); dprintf("single thread style, current pos=%zu\n", in->size); type = TYPE_SINGLE_THREAD; if (in->size == 9) { @@ -754,7 +754,7 @@ size_t ZSTDMT_decompressDCtx(ZSTDMT_DCtx * ctx, ZSTDMT_RdWr_t * rdwr) } else { /* invalid */ dprintf("not valid\n"); - return ZSTDMT_ERROR(data_error); + return ZSTDCB_ERROR(data_error); } } @@ -767,7 +767,7 @@ size_t ZSTDMT_decompressDCtx(ZSTDMT_DCtx * ctx, ZSTDMT_RdWr_t * rdwr) ctx->threads = 1; ctx->cwork = (cwork_t *) malloc(sizeof(cwork_t)); if (!ctx->cwork) - return ZSTDMT_ERROR(memory_allocation); + return ZSTDCB_ERROR(memory_allocation); w = &ctx->cwork[0]; w->in.buf = in->buf; w->in.size = in->size; @@ -775,7 +775,7 @@ size_t ZSTDMT_decompressDCtx(ZSTDMT_DCtx * ctx, ZSTDMT_RdWr_t * rdwr) w->ctx = ctx; w->dctx = ZSTD_createDStream(); if (!w->dctx) - return ZSTDMT_ERROR(memory_allocation); + return ZSTDCB_ERROR(memory_allocation); /* test, if pt_decompress is better... */ return st_decompress(ctx); @@ -785,7 +785,7 @@ size_t ZSTDMT_decompressDCtx(ZSTDMT_DCtx * ctx, ZSTDMT_RdWr_t * rdwr) ctx->threads = ctx->threadswanted; ctx->cwork = (cwork_t *) malloc(sizeof(cwork_t) * ctx->threads); if (!ctx->cwork) - return ZSTDMT_ERROR(memory_allocation); + return ZSTDCB_ERROR(memory_allocation); for (t = 0; t < ctx->threads; t++) { w = &ctx->cwork[t]; @@ -796,7 +796,7 @@ size_t ZSTDMT_decompressDCtx(ZSTDMT_DCtx * ctx, ZSTDMT_RdWr_t * rdwr) w->ctx = ctx; w->dctx = ZSTD_createDStream(); if (!w->dctx) - return ZSTDMT_ERROR(memory_allocation); + return ZSTDCB_ERROR(memory_allocation); } /* real multi threaded, init pthread's */ @@ -843,7 +843,7 @@ size_t ZSTDMT_decompressDCtx(ZSTDMT_DCtx * ctx, ZSTDMT_RdWr_t * rdwr) } /* returns current uncompressed data size */ -size_t ZSTDMT_GetInsizeDCtx(ZSTDMT_DCtx * ctx) +size_t ZSTDCB_GetInsizeDCtx(ZSTDCB_DCtx * ctx) { if (!ctx) return 0; @@ -852,7 +852,7 @@ size_t ZSTDMT_GetInsizeDCtx(ZSTDMT_DCtx * ctx) } /* returns the current compressed data size */ -size_t ZSTDMT_GetOutsizeDCtx(ZSTDMT_DCtx * ctx) +size_t ZSTDCB_GetOutsizeDCtx(ZSTDCB_DCtx * ctx) { if (!ctx) return 0; @@ -861,7 +861,7 @@ size_t ZSTDMT_GetOutsizeDCtx(ZSTDMT_DCtx * ctx) } /* returns the current compressed frames */ -size_t ZSTDMT_GetFramesDCtx(ZSTDMT_DCtx * ctx) +size_t ZSTDCB_GetFramesDCtx(ZSTDCB_DCtx * ctx) { if (!ctx) return 0; @@ -869,7 +869,7 @@ size_t ZSTDMT_GetFramesDCtx(ZSTDMT_DCtx * ctx) return ctx->curframe; } -void ZSTDMT_freeDCtx(ZSTDMT_DCtx * ctx) +void ZSTDCB_freeDCtx(ZSTDCB_DCtx * ctx) { int t;