diff options
author | Sverker Eriksson <[email protected]> | 2013-02-13 19:14:37 +0100 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2013-02-13 19:15:13 +0100 |
commit | aabb9531d01fd414998115409d489c02b7761c9a (patch) | |
tree | b402eaf982bb5f1adf248ed0187b2e6b1a44cd03 /erts/emulator/beam/erl_nif.c | |
parent | 33168981eda974653471b13e328fa2a9d3c9d9f3 (diff) | |
parent | ef3566f48e08481821eee1c7260cdd4ca05fdefc (diff) | |
download | otp-aabb9531d01fd414998115409d489c02b7761c9a.tar.gz otp-aabb9531d01fd414998115409d489c02b7761c9a.tar.bz2 otp-aabb9531d01fd414998115409d489c02b7761c9a.zip |
Merge branch 'sverk/nif-cut-timeslice'
* sverk/nif-cut-timeslice:
erts: Add enif_consume_timeslice
OTP-10810
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 ** |