diff options
author | Kjell Winblad <[email protected]> | 2019-06-18 16:07:41 +0200 |
---|---|---|
committer | Kjell Winblad <[email protected]> | 2019-06-18 16:07:41 +0200 |
commit | 1d12eae751c9c14626365d32947a7931ce55dbba (patch) | |
tree | 116813e52e719589518e4066531ea5bd2460df44 /erts/emulator/beam/erl_process.h | |
parent | a9373f7f3ee139a62207235f2e197135df4d8aef (diff) | |
parent | f707dc058dc0aa880d6f2604acb7b420b082a69c (diff) | |
download | otp-1d12eae751c9c14626365d32947a7931ce55dbba.tar.gz otp-1d12eae751c9c14626365d32947a7931ce55dbba.tar.bz2 otp-1d12eae751c9c14626365d32947a7931ce55dbba.zip |
Merge branch 'kjell/stdlib/ets_ordered_set_slow_react/OTP-15906' into maint
* kjell/stdlib/ets_ordered_set_slow_react/OTP-15906:
ETS ordered_set: Improvements to the CA tree implementation
Diffstat (limited to 'erts/emulator/beam/erl_process.h')
-rw-r--r-- | erts/emulator/beam/erl_process.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/erts/emulator/beam/erl_process.h b/erts/emulator/beam/erl_process.h index bbf50b4189..0d6b512f78 100644 --- a/erts/emulator/beam/erl_process.h +++ b/erts/emulator/beam/erl_process.h @@ -2632,6 +2632,9 @@ void erts_notify_inc_runq(ErtsRunQueue *runq); void erts_sched_finish_poke(ErtsSchedulerSleepInfo *, erts_aint32_t); ERTS_GLB_INLINE void erts_sched_poke(ErtsSchedulerSleepInfo *ssi); void erts_aux_thread_poke(void); +ERTS_GLB_INLINE Uint32 erts_sched_local_random_hash_64_to_32_shift(Uint64 key); +ERTS_GLB_INLINE Uint32 erts_sched_local_random(Uint additional_seed); + #if ERTS_GLB_INLINE_INCL_FUNC_DEF @@ -2648,6 +2651,39 @@ erts_sched_poke(ErtsSchedulerSleepInfo *ssi) } +/* + * Source: https://gist.github.com/badboy/6267743 + * http://web.archive.org/web/20071223173210/http://www.concentric.net/~Ttwang/tech/inthash.htm + */ +ERTS_GLB_INLINE +Uint32 erts_sched_local_random_hash_64_to_32_shift(Uint64 key) +{ + key = (~key) + (key << 18); /* key = (key << 18) - key - 1; */ + key = key ^ (key >> 31); + key = (key + (key << 2)) + (key << 4); + key = key ^ (key >> 11); + key = key + (key << 6); + key = key ^ (key >> 22); + return (Uint32) key; +} + +/* + * This function attempts to return a random number based on the state + * of the scheduler, the current process and the additional_seed + * parameter. + */ +ERTS_GLB_INLINE +Uint32 erts_sched_local_random(Uint additional_seed) +{ + ErtsSchedulerData *esdp = erts_get_scheduler_data(); + Uint64 seed = + additional_seed + + esdp->reductions + + esdp->current_process->fcalls + + (((Uint64)esdp->no) << 32); + return erts_sched_local_random_hash_64_to_32_shift(seed); +} + #endif /* #if ERTS_GLB_INLINE_INCL_FUNC_DEF */ |