zstd-ruby 1.3.1.1 → 1.3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/ext/zstdruby/libzstd/.gitignore +1 -0
- data/ext/zstdruby/libzstd/Makefile +40 -26
- data/ext/zstdruby/libzstd/README.md +68 -45
- data/ext/zstdruby/libzstd/common/bitstream.h +35 -23
- data/ext/zstdruby/libzstd/common/compiler.h +1 -0
- data/ext/zstdruby/libzstd/common/error_private.c +4 -2
- data/ext/zstdruby/libzstd/common/error_private.h +4 -4
- data/ext/zstdruby/libzstd/common/fse.h +1 -1
- data/ext/zstdruby/libzstd/common/huf.h +1 -1
- data/ext/zstdruby/libzstd/common/mem.h +1 -0
- data/ext/zstdruby/libzstd/common/pool.c +61 -46
- data/ext/zstdruby/libzstd/common/pool.h +4 -0
- data/ext/zstdruby/libzstd/common/threading.c +11 -15
- data/ext/zstdruby/libzstd/common/threading.h +52 -32
- data/ext/zstdruby/libzstd/common/zstd_common.c +2 -2
- data/ext/zstdruby/libzstd/common/zstd_errors.h +3 -1
- data/ext/zstdruby/libzstd/common/zstd_internal.h +95 -21
- data/ext/zstdruby/libzstd/compress/fse_compress.c +3 -1
- data/ext/zstdruby/libzstd/compress/huf_compress.c +4 -3
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +922 -2102
- data/ext/zstdruby/libzstd/compress/zstd_compress.h +307 -0
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +308 -0
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +28 -0
- data/ext/zstdruby/libzstd/compress/zstd_fast.c +242 -0
- data/ext/zstdruby/libzstd/compress/zstd_fast.h +30 -0
- data/ext/zstdruby/libzstd/compress/zstd_lazy.c +749 -0
- data/ext/zstdruby/libzstd/compress/zstd_lazy.h +38 -0
- data/ext/zstdruby/libzstd/compress/zstd_ldm.c +707 -0
- data/ext/zstdruby/libzstd/compress/zstd_ldm.h +67 -0
- data/ext/zstdruby/libzstd/compress/zstd_opt.c +957 -0
- data/ext/zstdruby/libzstd/compress/zstd_opt.h +14 -922
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +210 -133
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +20 -3
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +373 -196
- data/ext/zstdruby/libzstd/deprecated/zbuff.h +1 -0
- data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +1 -0
- data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +1 -0
- data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +1 -0
- data/ext/zstdruby/libzstd/dictBuilder/cover.c +33 -22
- data/ext/zstdruby/libzstd/dictBuilder/zdict.c +8 -5
- data/ext/zstdruby/libzstd/dictBuilder/zdict.h +1 -0
- data/ext/zstdruby/libzstd/dll/example/Makefile +5 -5
- data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v01.c +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v01.h +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v02.c +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v02.h +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v03.c +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v03.h +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v04.c +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v04.h +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v05.c +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v05.h +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v06.c +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v06.h +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v07.c +1 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v07.h +1 -0
- data/ext/zstdruby/libzstd/zstd.h +366 -118
- data/lib/zstd-ruby/version.rb +1 -1
- metadata +11 -1
@@ -184,7 +184,7 @@ FSE_PUBLIC_API size_t FSE_writeNCount (void* buffer, size_t bufferSize, const sh
|
|
184
184
|
/*! Constructor and Destructor of FSE_CTable.
|
185
185
|
Note that FSE_CTable size depends on 'tableLog' and 'maxSymbolValue' */
|
186
186
|
typedef unsigned FSE_CTable; /* don't allocate that. It's only meant to be more restrictive than void* */
|
187
|
-
FSE_PUBLIC_API FSE_CTable* FSE_createCTable (unsigned
|
187
|
+
FSE_PUBLIC_API FSE_CTable* FSE_createCTable (unsigned maxSymbolValue, unsigned tableLog);
|
188
188
|
FSE_PUBLIC_API void FSE_freeCTable (FSE_CTable* ct);
|
189
189
|
|
190
190
|
/*! FSE_buildCTable():
|
@@ -242,7 +242,7 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
|
242
242
|
|
243
243
|
/** HUF_readCTable() :
|
244
244
|
* Loading a CTable saved with HUF_writeCTable() */
|
245
|
-
size_t HUF_readCTable (HUF_CElt* CTable, unsigned
|
245
|
+
size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize);
|
246
246
|
|
247
247
|
|
248
248
|
/*
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
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.
|
8
9
|
*/
|
9
10
|
|
10
11
|
#ifndef MEM_H_MODULE
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
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.
|
8
9
|
*/
|
9
10
|
|
10
11
|
|
@@ -25,13 +26,14 @@
|
|
25
26
|
|
26
27
|
/* A job is a function and an opaque argument */
|
27
28
|
typedef struct POOL_job_s {
|
28
|
-
|
29
|
-
|
29
|
+
POOL_function function;
|
30
|
+
void *opaque;
|
30
31
|
} POOL_job;
|
31
32
|
|
32
33
|
struct POOL_ctx_s {
|
34
|
+
ZSTD_customMem customMem;
|
33
35
|
/* Keep track of the threads */
|
34
|
-
|
36
|
+
ZSTD_pthread_t *threads;
|
35
37
|
size_t numThreads;
|
36
38
|
|
37
39
|
/* The queue is a circular buffer */
|
@@ -46,11 +48,11 @@ struct POOL_ctx_s {
|
|
46
48
|
int queueEmpty;
|
47
49
|
|
48
50
|
/* The mutex protects the queue */
|
49
|
-
|
51
|
+
ZSTD_pthread_mutex_t queueMutex;
|
50
52
|
/* Condition variable for pushers to wait on when the queue is full */
|
51
|
-
|
53
|
+
ZSTD_pthread_cond_t queuePushCond;
|
52
54
|
/* Condition variables for poppers to wait on when the queue is empty */
|
53
|
-
|
55
|
+
ZSTD_pthread_cond_t queuePopCond;
|
54
56
|
/* Indicates if the queue is shutting down */
|
55
57
|
int shutdown;
|
56
58
|
};
|
@@ -65,14 +67,14 @@ static void* POOL_thread(void* opaque) {
|
|
65
67
|
if (!ctx) { return NULL; }
|
66
68
|
for (;;) {
|
67
69
|
/* Lock the mutex and wait for a non-empty queue or until shutdown */
|
68
|
-
|
70
|
+
ZSTD_pthread_mutex_lock(&ctx->queueMutex);
|
69
71
|
|
70
72
|
while (ctx->queueEmpty && !ctx->shutdown) {
|
71
|
-
|
73
|
+
ZSTD_pthread_cond_wait(&ctx->queuePopCond, &ctx->queueMutex);
|
72
74
|
}
|
73
75
|
/* empty => shutting down: so stop */
|
74
76
|
if (ctx->queueEmpty) {
|
75
|
-
|
77
|
+
ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
|
76
78
|
return opaque;
|
77
79
|
}
|
78
80
|
/* Pop a job off the queue */
|
@@ -81,28 +83,32 @@ static void* POOL_thread(void* opaque) {
|
|
81
83
|
ctx->numThreadsBusy++;
|
82
84
|
ctx->queueEmpty = ctx->queueHead == ctx->queueTail;
|
83
85
|
/* Unlock the mutex, signal a pusher, and run the job */
|
84
|
-
|
85
|
-
|
86
|
+
ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
|
87
|
+
ZSTD_pthread_cond_signal(&ctx->queuePushCond);
|
86
88
|
|
87
89
|
job.function(job.opaque);
|
88
90
|
|
89
91
|
/* If the intended queue size was 0, signal after finishing job */
|
90
92
|
if (ctx->queueSize == 1) {
|
91
|
-
|
93
|
+
ZSTD_pthread_mutex_lock(&ctx->queueMutex);
|
92
94
|
ctx->numThreadsBusy--;
|
93
|
-
|
94
|
-
|
95
|
+
ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
|
96
|
+
ZSTD_pthread_cond_signal(&ctx->queuePushCond);
|
95
97
|
} }
|
96
98
|
} /* for (;;) */
|
97
99
|
/* Unreachable */
|
98
100
|
}
|
99
101
|
|
100
|
-
POOL_ctx
|
101
|
-
|
102
|
+
POOL_ctx* POOL_create(size_t numThreads, size_t queueSize) {
|
103
|
+
return POOL_create_advanced(numThreads, queueSize, ZSTD_defaultCMem);
|
104
|
+
}
|
105
|
+
|
106
|
+
POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize, ZSTD_customMem customMem) {
|
107
|
+
POOL_ctx* ctx;
|
102
108
|
/* Check the parameters */
|
103
109
|
if (!numThreads) { return NULL; }
|
104
110
|
/* Allocate the context and zero initialize */
|
105
|
-
ctx = (POOL_ctx
|
111
|
+
ctx = (POOL_ctx*)ZSTD_calloc(sizeof(POOL_ctx), customMem);
|
106
112
|
if (!ctx) { return NULL; }
|
107
113
|
/* Initialize the job queue.
|
108
114
|
* It needs one extra space since one space is wasted to differentiate empty
|
@@ -114,19 +120,20 @@ POOL_ctx *POOL_create(size_t numThreads, size_t queueSize) {
|
|
114
120
|
ctx->queueTail = 0;
|
115
121
|
ctx->numThreadsBusy = 0;
|
116
122
|
ctx->queueEmpty = 1;
|
117
|
-
(void)
|
118
|
-
(void)
|
119
|
-
(void)
|
123
|
+
(void)ZSTD_pthread_mutex_init(&ctx->queueMutex, NULL);
|
124
|
+
(void)ZSTD_pthread_cond_init(&ctx->queuePushCond, NULL);
|
125
|
+
(void)ZSTD_pthread_cond_init(&ctx->queuePopCond, NULL);
|
120
126
|
ctx->shutdown = 0;
|
121
127
|
/* Allocate space for the thread handles */
|
122
|
-
ctx->threads = (
|
128
|
+
ctx->threads = (ZSTD_pthread_t*)ZSTD_malloc(numThreads * sizeof(ZSTD_pthread_t), customMem);
|
123
129
|
ctx->numThreads = 0;
|
130
|
+
ctx->customMem = customMem;
|
124
131
|
/* Check for errors */
|
125
132
|
if (!ctx->threads || !ctx->queue) { POOL_free(ctx); return NULL; }
|
126
133
|
/* Initialize the threads */
|
127
134
|
{ size_t i;
|
128
135
|
for (i = 0; i < numThreads; ++i) {
|
129
|
-
if (
|
136
|
+
if (ZSTD_pthread_create(&ctx->threads[i], NULL, &POOL_thread, ctx)) {
|
130
137
|
ctx->numThreads = i;
|
131
138
|
POOL_free(ctx);
|
132
139
|
return NULL;
|
@@ -139,37 +146,37 @@ POOL_ctx *POOL_create(size_t numThreads, size_t queueSize) {
|
|
139
146
|
/*! POOL_join() :
|
140
147
|
Shutdown the queue, wake any sleeping threads, and join all of the threads.
|
141
148
|
*/
|
142
|
-
static void POOL_join(POOL_ctx
|
149
|
+
static void POOL_join(POOL_ctx* ctx) {
|
143
150
|
/* Shut down the queue */
|
144
|
-
|
151
|
+
ZSTD_pthread_mutex_lock(&ctx->queueMutex);
|
145
152
|
ctx->shutdown = 1;
|
146
|
-
|
153
|
+
ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
|
147
154
|
/* Wake up sleeping threads */
|
148
|
-
|
149
|
-
|
155
|
+
ZSTD_pthread_cond_broadcast(&ctx->queuePushCond);
|
156
|
+
ZSTD_pthread_cond_broadcast(&ctx->queuePopCond);
|
150
157
|
/* Join all of the threads */
|
151
158
|
{ size_t i;
|
152
159
|
for (i = 0; i < ctx->numThreads; ++i) {
|
153
|
-
|
160
|
+
ZSTD_pthread_join(ctx->threads[i], NULL);
|
154
161
|
} }
|
155
162
|
}
|
156
163
|
|
157
164
|
void POOL_free(POOL_ctx *ctx) {
|
158
165
|
if (!ctx) { return; }
|
159
166
|
POOL_join(ctx);
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
167
|
+
ZSTD_pthread_mutex_destroy(&ctx->queueMutex);
|
168
|
+
ZSTD_pthread_cond_destroy(&ctx->queuePushCond);
|
169
|
+
ZSTD_pthread_cond_destroy(&ctx->queuePopCond);
|
170
|
+
ZSTD_free(ctx->queue, ctx->customMem);
|
171
|
+
ZSTD_free(ctx->threads, ctx->customMem);
|
172
|
+
ZSTD_free(ctx, ctx->customMem);
|
166
173
|
}
|
167
174
|
|
168
175
|
size_t POOL_sizeof(POOL_ctx *ctx) {
|
169
176
|
if (ctx==NULL) return 0; /* supports sizeof NULL */
|
170
177
|
return sizeof(*ctx)
|
171
178
|
+ ctx->queueSize * sizeof(POOL_job)
|
172
|
-
+ ctx->numThreads * sizeof(
|
179
|
+
+ ctx->numThreads * sizeof(ZSTD_pthread_t);
|
173
180
|
}
|
174
181
|
|
175
182
|
/**
|
@@ -191,12 +198,12 @@ void POOL_add(void* ctxVoid, POOL_function function, void *opaque) {
|
|
191
198
|
POOL_ctx* const ctx = (POOL_ctx*)ctxVoid;
|
192
199
|
if (!ctx) { return; }
|
193
200
|
|
194
|
-
|
201
|
+
ZSTD_pthread_mutex_lock(&ctx->queueMutex);
|
195
202
|
{ POOL_job const job = {function, opaque};
|
196
203
|
|
197
204
|
/* Wait until there is space in the queue for the new job */
|
198
205
|
while (isQueueFull(ctx) && !ctx->shutdown) {
|
199
|
-
|
206
|
+
ZSTD_pthread_cond_wait(&ctx->queuePushCond, &ctx->queueMutex);
|
200
207
|
}
|
201
208
|
/* The queue is still going => there is space */
|
202
209
|
if (!ctx->shutdown) {
|
@@ -205,8 +212,8 @@ void POOL_add(void* ctxVoid, POOL_function function, void *opaque) {
|
|
205
212
|
ctx->queueTail = (ctx->queueTail + 1) % ctx->queueSize;
|
206
213
|
}
|
207
214
|
}
|
208
|
-
|
209
|
-
|
215
|
+
ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
|
216
|
+
ZSTD_pthread_cond_signal(&ctx->queuePopCond);
|
210
217
|
}
|
211
218
|
|
212
219
|
#else /* ZSTD_MULTITHREAD not defined */
|
@@ -214,26 +221,34 @@ void POOL_add(void* ctxVoid, POOL_function function, void *opaque) {
|
|
214
221
|
|
215
222
|
/* We don't need any data, but if it is empty malloc() might return NULL. */
|
216
223
|
struct POOL_ctx_s {
|
217
|
-
|
224
|
+
int dummy;
|
218
225
|
};
|
226
|
+
static POOL_ctx g_ctx;
|
219
227
|
|
220
228
|
POOL_ctx* POOL_create(size_t numThreads, size_t queueSize) {
|
221
|
-
|
222
|
-
|
223
|
-
|
229
|
+
return POOL_create_advanced(numThreads, queueSize, ZSTD_defaultCMem);
|
230
|
+
}
|
231
|
+
|
232
|
+
POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize, ZSTD_customMem customMem) {
|
233
|
+
(void)numThreads;
|
234
|
+
(void)queueSize;
|
235
|
+
(void)customMem;
|
236
|
+
return &g_ctx;
|
224
237
|
}
|
225
238
|
|
226
239
|
void POOL_free(POOL_ctx* ctx) {
|
227
|
-
|
240
|
+
assert(!ctx || ctx == &g_ctx);
|
241
|
+
(void)ctx;
|
228
242
|
}
|
229
243
|
|
230
244
|
void POOL_add(void* ctx, POOL_function function, void* opaque) {
|
231
|
-
|
232
|
-
|
245
|
+
(void)ctx;
|
246
|
+
function(opaque);
|
233
247
|
}
|
234
248
|
|
235
249
|
size_t POOL_sizeof(POOL_ctx* ctx) {
|
236
250
|
if (ctx==NULL) return 0; /* supports sizeof NULL */
|
251
|
+
assert(ctx == &g_ctx);
|
237
252
|
return sizeof(*ctx);
|
238
253
|
}
|
239
254
|
|
@@ -5,6 +5,7 @@
|
|
5
5
|
* This source code is licensed under both the BSD-style license (found in the
|
6
6
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
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.
|
8
9
|
*/
|
9
10
|
|
10
11
|
#ifndef POOL_H
|
@@ -16,6 +17,7 @@ extern "C" {
|
|
16
17
|
|
17
18
|
|
18
19
|
#include <stddef.h> /* size_t */
|
20
|
+
#include "zstd_internal.h" /* ZSTD_customMem */
|
19
21
|
|
20
22
|
typedef struct POOL_ctx_s POOL_ctx;
|
21
23
|
|
@@ -27,6 +29,8 @@ typedef struct POOL_ctx_s POOL_ctx;
|
|
27
29
|
*/
|
28
30
|
POOL_ctx *POOL_create(size_t numThreads, size_t queueSize);
|
29
31
|
|
32
|
+
POOL_ctx *POOL_create_advanced(size_t numThreads, size_t queueSize, ZSTD_customMem customMem);
|
33
|
+
|
30
34
|
/*! POOL_free() :
|
31
35
|
Free a thread pool returned by POOL_create().
|
32
36
|
*/
|
@@ -2,9 +2,9 @@
|
|
2
2
|
* Copyright (c) 2016 Tino Reichardt
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
6
|
-
* LICENSE file in the root directory of this source tree
|
7
|
-
*
|
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
8
|
*
|
9
9
|
* You can contact the author at:
|
10
10
|
* - zstdmt source repository: https://github.com/mcmilk/zstdmt
|
@@ -14,12 +14,8 @@
|
|
14
14
|
* This file will hold wrapper for systems, which do not support pthreads
|
15
15
|
*/
|
16
16
|
|
17
|
-
/*
|
18
|
-
|
19
|
-
* (Visual C++: C4206 / GCC: -Wpedantic / Clang: -Wempty-translation-unit)
|
20
|
-
*/
|
21
|
-
#include <stddef.h>
|
22
|
-
|
17
|
+
/* create fake symbol to avoid empty trnaslation unit warning */
|
18
|
+
int g_ZSTD_threading_useles_symbol;
|
23
19
|
|
24
20
|
#if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
|
25
21
|
|
@@ -39,12 +35,12 @@
|
|
39
35
|
|
40
36
|
static unsigned __stdcall worker(void *arg)
|
41
37
|
{
|
42
|
-
|
38
|
+
ZSTD_pthread_t* const thread = (ZSTD_pthread_t*) arg;
|
43
39
|
thread->arg = thread->start_routine(thread->arg);
|
44
40
|
return 0;
|
45
41
|
}
|
46
42
|
|
47
|
-
int
|
43
|
+
int ZSTD_pthread_create(ZSTD_pthread_t* thread, const void* unused,
|
48
44
|
void* (*start_routine) (void*), void* arg)
|
49
45
|
{
|
50
46
|
(void)unused;
|
@@ -58,16 +54,16 @@ int pthread_create(pthread_t* thread, const void* unused,
|
|
58
54
|
return 0;
|
59
55
|
}
|
60
56
|
|
61
|
-
int
|
57
|
+
int ZSTD_pthread_join(ZSTD_pthread_t thread, void **value_ptr)
|
62
58
|
{
|
63
59
|
DWORD result;
|
64
60
|
|
65
|
-
if (!thread
|
61
|
+
if (!thread.handle) return 0;
|
66
62
|
|
67
|
-
result = WaitForSingleObject(thread
|
63
|
+
result = WaitForSingleObject(thread.handle, INFINITE);
|
68
64
|
switch (result) {
|
69
65
|
case WAIT_OBJECT_0:
|
70
|
-
if (value_ptr) *value_ptr = thread
|
66
|
+
if (value_ptr) *value_ptr = thread.arg;
|
71
67
|
return 0;
|
72
68
|
case WAIT_ABANDONED:
|
73
69
|
return EINVAL;
|
@@ -2,9 +2,9 @@
|
|
2
2
|
* Copyright (c) 2016 Tino Reichardt
|
3
3
|
* All rights reserved.
|
4
4
|
*
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
6
|
-
* LICENSE file in the root directory of this source tree
|
7
|
-
*
|
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
8
|
*
|
9
9
|
* You can contact the author at:
|
10
10
|
* - zstdmt source repository: https://github.com/mcmilk/zstdmt
|
@@ -37,35 +37,38 @@ extern "C" {
|
|
37
37
|
# define WIN32_LEAN_AND_MEAN
|
38
38
|
#endif
|
39
39
|
|
40
|
+
#undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */
|
40
41
|
#include <windows.h>
|
42
|
+
#undef ERROR
|
43
|
+
#define ERROR(name) ZSTD_ERROR(name)
|
44
|
+
|
41
45
|
|
42
46
|
/* mutex */
|
43
|
-
#define
|
44
|
-
#define
|
45
|
-
#define
|
46
|
-
#define
|
47
|
-
#define
|
47
|
+
#define ZSTD_pthread_mutex_t CRITICAL_SECTION
|
48
|
+
#define ZSTD_pthread_mutex_init(a, b) (InitializeCriticalSection((a)), 0)
|
49
|
+
#define ZSTD_pthread_mutex_destroy(a) DeleteCriticalSection((a))
|
50
|
+
#define ZSTD_pthread_mutex_lock(a) EnterCriticalSection((a))
|
51
|
+
#define ZSTD_pthread_mutex_unlock(a) LeaveCriticalSection((a))
|
48
52
|
|
49
53
|
/* condition variable */
|
50
|
-
#define
|
51
|
-
#define
|
52
|
-
#define
|
53
|
-
#define
|
54
|
-
#define
|
55
|
-
#define
|
56
|
-
|
57
|
-
/*
|
54
|
+
#define ZSTD_pthread_cond_t CONDITION_VARIABLE
|
55
|
+
#define ZSTD_pthread_cond_init(a, b) (InitializeConditionVariable((a)), 0)
|
56
|
+
#define ZSTD_pthread_cond_destroy(a) /* No delete */
|
57
|
+
#define ZSTD_pthread_cond_wait(a, b) SleepConditionVariableCS((a), (b), INFINITE)
|
58
|
+
#define ZSTD_pthread_cond_signal(a) WakeConditionVariable((a))
|
59
|
+
#define ZSTD_pthread_cond_broadcast(a) WakeAllConditionVariable((a))
|
60
|
+
|
61
|
+
/* ZSTD_pthread_create() and ZSTD_pthread_join() */
|
58
62
|
typedef struct {
|
59
63
|
HANDLE handle;
|
60
64
|
void* (*start_routine)(void*);
|
61
65
|
void* arg;
|
62
|
-
}
|
66
|
+
} ZSTD_pthread_t;
|
63
67
|
|
64
|
-
int
|
68
|
+
int ZSTD_pthread_create(ZSTD_pthread_t* thread, const void* unused,
|
65
69
|
void* (*start_routine) (void*), void* arg);
|
66
70
|
|
67
|
-
|
68
|
-
int _pthread_join(pthread_t* thread, void** value_ptr);
|
71
|
+
int ZSTD_pthread_join(ZSTD_pthread_t thread, void** value_ptr);
|
69
72
|
|
70
73
|
/**
|
71
74
|
* add here more wrappers as required
|
@@ -76,23 +79,40 @@ int _pthread_join(pthread_t* thread, void** value_ptr);
|
|
76
79
|
/* === POSIX Systems === */
|
77
80
|
# include <pthread.h>
|
78
81
|
|
82
|
+
#define ZSTD_pthread_mutex_t pthread_mutex_t
|
83
|
+
#define ZSTD_pthread_mutex_init(a, b) pthread_mutex_init((a), (b))
|
84
|
+
#define ZSTD_pthread_mutex_destroy(a) pthread_mutex_destroy((a))
|
85
|
+
#define ZSTD_pthread_mutex_lock(a) pthread_mutex_lock((a))
|
86
|
+
#define ZSTD_pthread_mutex_unlock(a) pthread_mutex_unlock((a))
|
87
|
+
|
88
|
+
#define ZSTD_pthread_cond_t pthread_cond_t
|
89
|
+
#define ZSTD_pthread_cond_init(a, b) pthread_cond_init((a), (b))
|
90
|
+
#define ZSTD_pthread_cond_destroy(a) pthread_cond_destroy((a))
|
91
|
+
#define ZSTD_pthread_cond_wait(a, b) pthread_cond_wait((a), (b))
|
92
|
+
#define ZSTD_pthread_cond_signal(a) pthread_cond_signal((a))
|
93
|
+
#define ZSTD_pthread_cond_broadcast(a) pthread_cond_broadcast((a))
|
94
|
+
|
95
|
+
#define ZSTD_pthread_t pthread_t
|
96
|
+
#define ZSTD_pthread_create(a, b, c, d) pthread_create((a), (b), (c), (d))
|
97
|
+
#define ZSTD_pthread_join(a, b) pthread_join((a),(b))
|
98
|
+
|
79
99
|
#else /* ZSTD_MULTITHREAD not defined */
|
80
100
|
/* No multithreading support */
|
81
101
|
|
82
|
-
|
83
|
-
#define
|
84
|
-
#define
|
85
|
-
#define
|
86
|
-
#define
|
102
|
+
typedef int ZSTD_pthread_mutex_t;
|
103
|
+
#define ZSTD_pthread_mutex_init(a, b) ((void)a, 0)
|
104
|
+
#define ZSTD_pthread_mutex_destroy(a)
|
105
|
+
#define ZSTD_pthread_mutex_lock(a)
|
106
|
+
#define ZSTD_pthread_mutex_unlock(a)
|
87
107
|
|
88
|
-
|
89
|
-
#define
|
90
|
-
#define
|
91
|
-
#define
|
92
|
-
#define
|
93
|
-
#define
|
108
|
+
typedef int ZSTD_pthread_cond_t;
|
109
|
+
#define ZSTD_pthread_cond_init(a, b) ((void)a, 0)
|
110
|
+
#define ZSTD_pthread_cond_destroy(a)
|
111
|
+
#define ZSTD_pthread_cond_wait(a, b)
|
112
|
+
#define ZSTD_pthread_cond_signal(a)
|
113
|
+
#define ZSTD_pthread_cond_broadcast(a)
|
94
114
|
|
95
|
-
/* do not use
|
115
|
+
/* do not use ZSTD_pthread_t */
|
96
116
|
|
97
117
|
#endif /* ZSTD_MULTITHREAD */
|
98
118
|
|