From c0c3cc2b516408b673db3202815d52c39d91451e Mon Sep 17 00:00:00 2001 From: Patrik Nyblom Date: Fri, 7 Jun 2013 17:04:47 +0200 Subject: Teach crypto.c not to call enif_compute_timeslice with 0 --- lib/crypto/c_src/crypto.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/crypto/c_src/crypto.c b/lib/crypto/c_src/crypto.c index b07db47fd6..00abeb9990 100644 --- a/lib/crypto/c_src/crypto.c +++ b/lib/crypto/c_src/crypto.c @@ -143,13 +143,16 @@ } /* This shall correspond to the similar macro in crypto.erl */ -#define MAX_BYTES_TO_NIF 20000 /* Current value is: erlang:system_info(context_reductions) * 10 */ +/* Current value is: erlang:system_info(context_reductions) * 10 */ +#define MAX_BYTES_TO_NIF 20000 #define CONSUME_REDS(NifEnv, Ibin) \ do { \ - int _cost = ((Ibin).size * 100) / MAX_BYTES_TO_NIF; \ - (void) enif_consume_timeslice((NifEnv), \ - (_cost > 100) ? 100 : _cost); \ + int _cost = ((Ibin).size * 100) / MAX_BYTES_TO_NIF;\ + if (_cost) { \ + (void) enif_consume_timeslice((NifEnv), \ + (_cost > 100) ? 100 : _cost); \ + } \ } while (0) /* NIF interface declarations */ -- cgit v1.2.3