diff options
author | Hans Nilsson <[email protected]> | 2019-05-29 09:06:26 +0200 |
---|---|---|
committer | Hans Nilsson <[email protected]> | 2019-06-14 13:33:07 +0200 |
commit | d3e7944c621001c318014b249a456e7d336b7d9e (patch) | |
tree | 20aca61c8ef198a02bcc81184724e58012e022f5 /lib/crypto/c_src/mac.c | |
parent | 160cea3f655913b370650f93b0c8f6c1bd163e32 (diff) | |
download | otp-d3e7944c621001c318014b249a456e7d336b7d9e.tar.gz otp-d3e7944c621001c318014b249a456e7d336b7d9e.tar.bz2 otp-d3e7944c621001c318014b249a456e7d336b7d9e.zip |
crypto: Use dirty schedulers for the new mac_nif if large data
Diffstat (limited to 'lib/crypto/c_src/mac.c')
-rw-r--r-- | lib/crypto/c_src/mac.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/crypto/c_src/mac.c b/lib/crypto/c_src/mac.c index 91dd42314e..270c2f0fe1 100644 --- a/lib/crypto/c_src/mac.c +++ b/lib/crypto/c_src/mac.c @@ -123,9 +123,37 @@ struct mac_type_t* get_mac_type(ERL_NIF_TERM type) +/******************************************************************* + * + * Mac nif + * + ******************************************************************/ +ERL_NIF_TERM mac_one_time(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]); ERL_NIF_TERM mac_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {/* (MacType, SubType, Key, Text) */ + ErlNifBinary text; + + if (!enif_inspect_iolist_as_binary(env, argv[3], &text)) + return EXCP_BADARG(env, "Bad text"); + + if (text.size > INT_MAX) + return EXCP_BADARG(env, "Too long text"); + + /* Run long jobs on a dirty scheduler to not block the current emulator thread */ + if (text.size > MAX_BYTES_TO_NIF) { + return enif_schedule_nif(env, "mac_one_time", + ERL_NIF_DIRTY_JOB_CPU_BOUND, + mac_one_time, argc, argv); + } + + return mac_one_time(env, argc, argv); +} + + + +ERL_NIF_TERM mac_one_time(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{/* (MacType, SubType, Key, Text) */ ErlNifBinary key_bin, text; int ret_bin_alloc = 0; @@ -385,5 +413,3 @@ done: - - |