From a9570b0a5d361f39527ab034c4005c3927ed2df0 Mon Sep 17 00:00:00 2001 From: lwalkin Date: Fri, 10 Oct 2014 22:18:24 +0000 Subject: [PATCH] use consume_timeslice as intended --- c_src/decoder.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/c_src/decoder.c b/c_src/decoder.c index ad3e8d3..b37e056 100644 --- a/c_src/decoder.c +++ b/c_src/decoder.c @@ -754,8 +754,14 @@ decode_iter(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) start = d->i; while(d->i < bin.size) { //fprintf(stderr, "state: %d\r\n", dec_curr(d)); - if(should_yield(d->i - start, d->bytes_per_iter)) { - consume_timeslice(env, d->i - start, d->bytes_per_iter); + if(should_yield(d->i - start, d->bytes_per_iter) + /* A system could handle roughly 100kb per millisecond on a single core. + * So the total amount of work per millisecond is 100kb. + * We report the percentage of the time every (bytes_per_iter) bytes + * in hope that the system will ask as to yield. We don't yield until + * asked by the system according to our feedback (of questionable accuracy). + */ + && consume_timeslice(env, d->i - start, 100000)) { return enif_make_tuple5( env, st->atom_iter,