aboutsummaryrefslogtreecommitdiffstats
path: root/erts
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2012-02-15 17:08:47 +0100
committerSverker Eriksson <[email protected]>2012-02-21 15:32:07 +0100
commitcd63cd50bae6d98d6d56fa24674f14e7b9457a37 (patch)
treed29626de041a5212203858839cddfe45e3468feb /erts
parentdc2b0ecba50cbe6b2f2321b1f24579a0353ced18 (diff)
downloadotp-cd63cd50bae6d98d6d56fa24674f14e7b9457a37.tar.gz
otp-cd63cd50bae6d98d6d56fa24674f14e7b9457a37.tar.bz2
otp-cd63cd50bae6d98d6d56fa24674f14e7b9457a37.zip
erts: Refactor export staging lock
Renamed it export_staging_lock and made change it to ordinary mutex.
Diffstat (limited to 'erts')
-rw-r--r--erts/emulator/beam/code_ix.c5
-rw-r--r--erts/emulator/beam/export.c33
-rw-r--r--erts/emulator/beam/export.h6
3 files changed, 21 insertions, 23 deletions
diff --git a/erts/emulator/beam/code_ix.c b/erts/emulator/beam/code_ix.c
index 5565b51e7e..d4bf75558d 100644
--- a/erts/emulator/beam/code_ix.c
+++ b/erts/emulator/beam/code_ix.c
@@ -78,12 +78,13 @@ void erts_end_staging_code_ix(void)
void erts_activate_staging_code_ix(void)
{
ErtsCodeIndex ix;
- export_write_lock();
+ /* We need to this lock as we are now making the staging export table active */
+ export_staging_lock();
ix = erts_staging_code_ix();
erts_smp_atomic32_set_nob(&the_active_code_index, ix);
ix = (ix + 1) % ERTS_NUM_CODE_IX;
erts_smp_atomic32_set_nob(&the_staging_code_index, ix);
- export_write_unlock();
+ export_staging_unlock();
CIX_TRACE("activate");
}
diff --git a/erts/emulator/beam/export.c b/erts/emulator/beam/export.c
index 78a0b7d269..229641cb32 100644
--- a/erts/emulator/beam/export.c
+++ b/erts/emulator/beam/export.c
@@ -44,10 +44,10 @@ static erts_smp_atomic_t total_entries_bytes;
#include "erl_smp.h"
-erts_smp_rwmtx_t export_staging_lock; /* Locks the staging export table. */
-
-#define export_read_lock() erts_smp_rwmtx_rlock(&export_staging_lock)
-#define export_read_unlock() erts_smp_rwmtx_runlock(&export_staging_lock)
+/* This lock protects the staging export table from concurrent access
+ * AND it protects the staging table from becoming active.
+ */
+erts_smp_mtx_t export_staging_lock;
extern BeamInstr* em_call_error_handler;
extern BeamInstr* em_call_traced_function;
@@ -88,13 +88,13 @@ export_info(int to, void *to_arg)
#ifdef ERTS_SMP
int lock = !ERTS_IS_CRASH_DUMPING;
if (lock)
- export_read_lock();
+ export_staging_lock();
#endif
index_info(to, to_arg, &export_tables[erts_active_code_ix()]);
hash_info(to, to_arg, &export_tables[erts_staging_code_ix()].htable);
#ifdef ERTS_SMP
if (lock)
- export_read_unlock();
+ export_staging_unlock();
#endif
}
@@ -175,12 +175,9 @@ void
init_export_table(void)
{
HashFunctions f;
- erts_smp_rwmtx_opt_t rwmtx_opt = ERTS_SMP_RWMTX_OPT_DEFAULT_INITER;
int i;
- rwmtx_opt.type = ERTS_SMP_RWMTX_TYPE_FREQUENT_READ;
- rwmtx_opt.lived = ERTS_SMP_RWMTX_LONG_LIVED;
- erts_smp_rwmtx_init_opt(&export_staging_lock, &rwmtx_opt, "export_tab");
+ erts_smp_mtx_init(&export_staging_lock, "export_tab");
erts_smp_atomic_init_nob(&total_entries_bytes, 0);
f.hash = (H_FUN) export_hash;
@@ -287,10 +284,10 @@ erts_export_put(Eterm mod, Eterm func, unsigned int arity)
ASSERT(is_atom(mod));
ASSERT(is_atom(func));
- export_write_lock();
+ export_staging_lock();
ee = (struct export_entry*) index_put_entry(&export_tables[code_ix],
init_template(&templ, mod, func, arity));
- export_write_unlock();
+ export_staging_unlock();
return ee->ep;
}
@@ -320,7 +317,7 @@ erts_export_get_or_make_stub(Eterm mod, Eterm func, unsigned int arity)
* The code is not loaded (yet). Put the export in the staging
* export table, to avoid having to lock the active export table.
*/
- export_write_lock();
+ export_staging_lock();
if (erts_active_code_ix() == code_ix) {
struct export_templ templ;
struct export_entry* entry;
@@ -335,7 +332,7 @@ erts_export_get_or_make_stub(Eterm mod, Eterm func, unsigned int arity)
ASSERT(!retrying);
IF_DEBUG(retrying = 1);
}
- export_write_unlock();
+ export_staging_unlock();
}
} while (!ep);
return ep;
@@ -355,11 +352,11 @@ int export_table_sz(void)
{
int i, bytes = 0;
- export_read_lock();
+ export_staging_lock();
for (i=0; i<ERTS_NUM_CODE_IX; i++) {
bytes += index_table_sz(&export_tables[i]);
}
- export_read_unlock();
+ export_staging_unlock();
return bytes;
}
int export_entries_sz(void)
@@ -392,7 +389,7 @@ void export_start_staging(void)
ASSERT(dst_ix != src_ix);
ASSERT(debug_start_load_ix == -1);
- export_write_lock();
+ export_staging_lock();
/*
* Insert all entries in src into dst table
*/
@@ -402,7 +399,7 @@ void export_start_staging(void)
dst_entry = (struct export_entry*) index_put_entry(dst, src_entry);
ASSERT(entry_to_blob(src_entry) == entry_to_blob(dst_entry));
}
- export_write_unlock();
+ export_staging_unlock();
IF_DEBUG(debug_start_load_ix = dst_ix);
}
diff --git a/erts/emulator/beam/export.h b/erts/emulator/beam/export.h
index 45c98d6bbb..ec9fcb26f2 100644
--- a/erts/emulator/beam/export.h
+++ b/erts/emulator/beam/export.h
@@ -74,9 +74,9 @@ Export *export_get(Export*);
void export_start_staging(void);
void export_end_staging(int commit);
-extern erts_smp_rwmtx_t export_staging_lock;
-#define export_write_lock() erts_smp_rwmtx_rwlock(&export_staging_lock)
-#define export_write_unlock() erts_smp_rwmtx_rwunlock(&export_staging_lock)
+extern erts_smp_mtx_t export_staging_lock;
+#define export_staging_lock() erts_smp_mtx_lock(&export_staging_lock)
+#define export_staging_unlock() erts_smp_mtx_unlock(&export_staging_lock)
#include "beam_load.h" /* For em_* extern declarations */
#define ExportIsBuiltIn(EntryPtr) \