diff options
author | Sverker Eriksson <[email protected]> | 2013-02-05 18:50:00 +0100 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2013-02-13 19:04:43 +0100 |
commit | ef3566f48e08481821eee1c7260cdd4ca05fdefc (patch) | |
tree | 44d71c2e89c712511cf3acbc38c0f14284ea8b97 /erts/emulator/beam/erl_nif.c | |
parent | 68b804f34d4ec420d86953e3f519179a40fbee8f (diff) | |
download | otp-ef3566f48e08481821eee1c7260cdd4ca05fdefc.tar.gz otp-ef3566f48e08481821eee1c7260cdd4ca05fdefc.tar.bz2 otp-ef3566f48e08481821eee1c7260cdd4ca05fdefc.zip |
erts: Add enif_consume_timeslice
Diffstat (limited to 'erts/emulator/beam/erl_nif.c')
-rw-r--r-- | erts/emulator/beam/erl_nif.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/erts/emulator/beam/erl_nif.c b/erts/emulator/beam/erl_nif.c index 068f904b76..d4c2b5bdcc 100644 --- a/erts/emulator/beam/erl_nif.c +++ b/erts/emulator/beam/erl_nif.c @@ -1443,6 +1443,19 @@ void* enif_dlsym(void* handle, const char* symbol, return ret; } +int enif_consume_timeslice(ErlNifEnv* env, int percent) +{ + Sint reds; + + ASSERT(is_proc_bound(env) && percent >= 1 && percent <= 100); + if (percent < 1) percent = 1; + else if (percent > 100) percent = 100; + + reds = ((CONTEXT_REDS+99) / 100) * percent; + ASSERT(reds > 0 && reds <= CONTEXT_REDS); + BUMP_REDS(env->proc, reds); + return ERTS_BIF_REDS_LEFT(env->proc) == 0; +} /*************************************************************************** ** load_nif/2 ** |