aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/safe_hash.c
diff options
context:
space:
mode:
authorJohn Högberg <[email protected]>2017-06-22 13:22:13 +0200
committerJohn Högberg <[email protected]>2017-07-06 12:29:42 +0200
commitf3fa8288287072195baa791ee11d5480d3cd45ff (patch)
tree7099c828834a43fde1c3fde0a6c151bdf9042807 /erts/emulator/beam/safe_hash.c
parente9bb277cc5cc8326c3c90ed82954f2ee14c1844b (diff)
downloadotp-f3fa8288287072195baa791ee11d5480d3cd45ff.tar.gz
otp-f3fa8288287072195baa791ee11d5480d3cd45ff.tar.bz2
otp-f3fa8288287072195baa791ee11d5480d3cd45ff.zip
Allow toggling lock counting at runtime
The implementation is still hidden behind ERTS_ENABLE_LOCK_COUNT, and all categories are still enabled by default, but the actual counting can be toggled at will. OTP-13170
Diffstat (limited to 'erts/emulator/beam/safe_hash.c')
-rw-r--r--erts/emulator/beam/safe_hash.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/erts/emulator/beam/safe_hash.c b/erts/emulator/beam/safe_hash.c
index 30b26a7296..527c9efeca 100644
--- a/erts/emulator/beam/safe_hash.c
+++ b/erts/emulator/beam/safe_hash.c
@@ -155,7 +155,8 @@ int safe_hash_table_sz(SafeHash *h)
** Init a pre allocated or static hash structure
** and allocate buckets. NOT SAFE
*/
-SafeHash* safe_hash_init(ErtsAlcType_t type, SafeHash* h, char* name, int size, SafeHashFunctions fun)
+SafeHash* safe_hash_init(ErtsAlcType_t type, SafeHash* h, char* name, erts_lock_flags_t flags,
+ int size, SafeHashFunctions fun)
{
int i, bytes;
@@ -170,7 +171,8 @@ SafeHash* safe_hash_init(ErtsAlcType_t type, SafeHash* h, char* name, int size,
erts_smp_atomic_init_nob(&h->is_rehashing, 0);
erts_smp_atomic_init_nob(&h->nitems, 0);
for (i=0; i<SAFE_HASH_LOCK_CNT; i++) {
- erts_smp_mtx_init(&h->lock_vec[i].mtx,"safe_hash");
+ erts_smp_mtx_init(&h->lock_vec[i].mtx, "safe_hash", NIL,
+ flags);
}
return h;
}
@@ -273,5 +275,22 @@ void safe_hash_for_each(SafeHash* h, void (*func)(void *, void *), void *func_ar
}
}
+#ifdef ERTS_ENABLE_LOCK_COUNT
+void erts_lcnt_enable_hash_lock_count(SafeHash *h, erts_lock_flags_t flags, int enable) {
+ int i;
+
+ for(i = 0; i < SAFE_HASH_LOCK_CNT; i++) {
+ erts_smp_mtx_t *lock = &h->lock_vec[i].mtx;
+
+ if(enable) {
+ erts_lcnt_install_new_lock_info(&lock->lcnt, "safe_hash", NIL,
+ ERTS_LOCK_TYPE_MUTEX | flags);
+ } else {
+ erts_lcnt_uninstall(&lock->lcnt);
+ }
+ }
+}
+#endif /* ERTS_ENABLE_LOCK_COUNT */
+
#endif /* !ERTS_SYS_CONTINOUS_FD_NUMBERS */