aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2013-02-13 19:14:37 +0100
committerSverker Eriksson <[email protected]>2013-02-13 19:15:13 +0100
commitaabb9531d01fd414998115409d489c02b7761c9a (patch)
treeb402eaf982bb5f1adf248ed0187b2e6b1a44cd03 /erts/emulator/beam
parent33168981eda974653471b13e328fa2a9d3c9d9f3 (diff)
parentef3566f48e08481821eee1c7260cdd4ca05fdefc (diff)
downloadotp-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')
-rw-r--r--erts/emulator/beam/erl_nif.c13
-rw-r--r--erts/emulator/beam/erl_nif.h5
-rw-r--r--erts/emulator/beam/erl_nif_api_funcs.h2
3 files changed, 18 insertions, 2 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 **
diff --git a/erts/emulator/beam/erl_nif.h b/erts/emulator/beam/erl_nif.h
index 93e56332e1..62aebcab6c 100644
--- a/erts/emulator/beam/erl_nif.h
+++ b/erts/emulator/beam/erl_nif.h
@@ -32,10 +32,11 @@
** 2.0: R14A
** 2.1: R14B02 "vm_variant"
** 2.2: R14B03 enif_is_exception
-** 2.3: R15 enif_make_reverse_list
+** 2.3: R15 enif_make_reverse_list, enif_is_number
+** 2.4: R16 enif_consume_timeslice
*/
#define ERL_NIF_MAJOR_VERSION 2
-#define ERL_NIF_MINOR_VERSION 3
+#define ERL_NIF_MINOR_VERSION 4
#include <stdlib.h>
diff --git a/erts/emulator/beam/erl_nif_api_funcs.h b/erts/emulator/beam/erl_nif_api_funcs.h
index af27573433..2f841645e1 100644
--- a/erts/emulator/beam/erl_nif_api_funcs.h
+++ b/erts/emulator/beam/erl_nif_api_funcs.h
@@ -140,6 +140,7 @@ ERL_NIF_API_FUNC_DECL(int,enif_make_reverse_list,(ErlNifEnv*, ERL_NIF_TERM term,
ERL_NIF_API_FUNC_DECL(int,enif_is_number,(ErlNifEnv*, ERL_NIF_TERM term));
ERL_NIF_API_FUNC_DECL(void*,enif_dlopen,(const char* lib, void (*err_handler)(void*,const char*), void* err_arg));
ERL_NIF_API_FUNC_DECL(void*,enif_dlsym,(void* handle, const char* symbol, void (*err_handler)(void*,const char*), void* err_arg));
+ERL_NIF_API_FUNC_DECL(int,enif_consume_timeslice,(ErlNifEnv*, int percent));
/*
** Add new entries here to keep compatibility on Windows!!!
@@ -264,6 +265,7 @@ ERL_NIF_API_FUNC_DECL(void*,enif_dlsym,(void* handle, const char* symbol, void (
# define enif_is_number ERL_NIF_API_FUNC_MACRO(enif_is_number)
# define enif_dlopen ERL_NIF_API_FUNC_MACRO(enif_dlopen)
# define enif_dlsym ERL_NIF_API_FUNC_MACRO(enif_dlsym)
+# define enif_consume_timeslice ERL_NIF_API_FUNC_MACRO(enif_consume_timeslice)
/*
** Add new entries here