Project

General

Profile

Feature #11625 ยป sha1gvl.diff

tenderlovemaking (Aaron Patterson), 10/27/2015 09:41 PM

View differences:

ext/digest/digest.c
624 624
    TypedData_Get_Struct(self, void, &digest_type, pctx);
625 625

  
626 626
    StringValue(str);
627
    str = rb_str_new_frozen(str);
627 628
    algo->update_func(pctx, (unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str));
628 629
    RB_GC_GUARD(str);
629 630

  
ext/digest/sha1/sha1.c
18 18
 */
19 19

  
20 20
#include "sha1.h"
21
#include <ruby/thread.h>
21 22

  
22 23
#define SHA1HANDSOFF		/* Copies data before messing with it. */
23 24

  
......
218 219
/*
219 220
 * Run your data through this.
220 221
 */
221
void SHA1_Update(SHA1_CTX *context, const uint8_t *data, size_t len)
222
static void SHA1_Update(SHA1_CTX *context, const uint8_t *data, size_t len)
222 223
{
223 224
    uint32_t i, j;
224 225

  
......
241 242
    (void)memcpy(&context->buffer[j], &data[i], len - i);
242 243
}
243 244

  
245
struct unpack_nogvl {
246
    SHA1_CTX *context;
247
    const uint8_t *data;
248
    size_t len;
249
};
250

  
251
void * SHA1_UpdateNoGVLUnpack(void * ptr)
252
{
253
    struct unpack_nogvl * args;
254
    args = ptr;
255
    SHA1_Update(args->context, args->data, args->len);
256
    return NULL;
257
}
258

  
259
void SHA1_UpdateNoGVL(SHA1_CTX *context, const uint8_t *data, size_t len)
260
{
261
    struct unpack_nogvl args;
262
    args.context = context;
263
    args.data = data;
264
    args.len = len;
265

  
266
    rb_thread_call_without_gvl(SHA1_UpdateNoGVLUnpack, &args, NULL, NULL);
267

  
268
    return;
269
}
244 270

  
245 271
/*
246 272
 * Add padding and return the message digest.
247 273
 */
248
int SHA1_Finish(SHA1_CTX* context, uint8_t digest[20])
274
static int SHA1_Finish(SHA1_CTX* context, uint8_t digest[20])
249 275
{
250 276
    size_t i;
251 277
    uint8_t finalcount[8];
......
269 295
    }
270 296
    return 1;
271 297
}
298

  
299
struct finish_nogvl {
300
    SHA1_CTX *context;
301
    uint8_t *digest;
302
};
303

  
304
void * SHA1_FinishNoGVLUnpack(void * ptr)
305
{
306
    struct finish_nogvl * args;
307
    args = ptr;
308
    SHA1_Finish(args->context, args->digest);
309
    return NULL;
310
}
311

  
312
int SHA1_FinishNoGVL(SHA1_CTX* context, uint8_t digest[20])
313
{
314
    struct finish_nogvl args;
315
    args.context = context;
316
    args.digest = digest;
317

  
318
    rb_thread_call_without_gvl(SHA1_FinishNoGVLUnpack, &args, NULL, NULL);
319
    return 1;
320
}
321

  
ext/digest/sha1/sha1.h
23 23
/* avoid name clash */
24 24
#define SHA1_Transform	rb_Digest_SHA1_Transform
25 25
#define SHA1_Init	rb_Digest_SHA1_Init
26
#define SHA1_Update	rb_Digest_SHA1_Update
27
#define SHA1_Finish	rb_Digest_SHA1_Finish
28 26
#endif
29 27

  
30 28
void	SHA1_Transform _((uint32_t state[5], const uint8_t buffer[64]));
31 29
int	SHA1_Init _((SHA1_CTX *context));
32
void	SHA1_Update _((SHA1_CTX *context, const uint8_t *data, size_t len));
33
int	SHA1_Finish _((SHA1_CTX *context, uint8_t digest[20]));
30
void	SHA1_UpdateNoGVL _((SHA1_CTX *context, const uint8_t *data, size_t len));
31
int	SHA1_FinishNoGVL _((SHA1_CTX *context, uint8_t digest[20]));
34 32

  
35 33
#define SHA1_BLOCK_LENGTH		64
36 34
#define SHA1_DIGEST_LENGTH		20
ext/digest/sha1/sha1init.c
16 16
    SHA1_BLOCK_LENGTH,
17 17
    sizeof(SHA1_CTX),
18 18
    (rb_digest_hash_init_func_t)SHA1_Init,
19
    (rb_digest_hash_update_func_t)SHA1_Update,
20
    (rb_digest_hash_finish_func_t)SHA1_Finish,
19
    (rb_digest_hash_update_func_t)SHA1_UpdateNoGVL,
20
    (rb_digest_hash_finish_func_t)SHA1_FinishNoGVL,
21 21
};
22 22

  
23 23
/*