aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/code_ix.c
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2012-02-15 15:12:18 +0100
committerSverker Eriksson <[email protected]>2012-02-21 15:32:07 +0100
commitdc2b0ecba50cbe6b2f2321b1f24579a0353ced18 (patch)
tree0ad297a07792533c1d2820c5ca69a886f3239e03 /erts/emulator/beam/code_ix.c
parentc4a8cc5914157c70ced742d957ec0e8d9c618164 (diff)
downloadotp-dc2b0ecba50cbe6b2f2321b1f24579a0353ced18.tar.gz
otp-dc2b0ecba50cbe6b2f2321b1f24579a0353ced18.tar.bz2
otp-dc2b0ecba50cbe6b2f2321b1f24579a0353ced18.zip
erts: Activate staged code in a thread safe way
Activation of staged code is scheduled for a later moment when all schedulers have done a full memory barrier. This allow them to read active code index while executing without any memory barriers at all.
Diffstat (limited to 'erts/emulator/beam/code_ix.c')
-rw-r--r--erts/emulator/beam/code_ix.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/erts/emulator/beam/code_ix.c b/erts/emulator/beam/code_ix.c
index a1db003127..5565b51e7e 100644
--- a/erts/emulator/beam/code_ix.c
+++ b/erts/emulator/beam/code_ix.c
@@ -66,22 +66,25 @@ void erts_start_staging_code_ix(void)
}
-void erts_commit_staging_code_ix(void)
+void erts_end_staging_code_ix(void)
{
beam_catches_end_staging(1);
export_end_staging(1);
module_end_staging(1);
erts_end_staging_ranges(1);
- {
- ErtsCodeIndex ix;
- export_write_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();
- }
- CIX_TRACE("commit");
+ CIX_TRACE("end");
+}
+
+void erts_activate_staging_code_ix(void)
+{
+ ErtsCodeIndex ix;
+ export_write_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();
+ CIX_TRACE("activate");
}
void erts_abort_staging_code_ix(void)
@@ -121,7 +124,7 @@ int erts_try_lock_code_ix(Process* c_p)
/* Unlock code_ix (resume all waiters)
*/
-void erts_unlock_code_ix()
+void erts_unlock_code_ix(void)
{
erts_smp_mtx_lock(&the_code_ix_queue_lock);
while (the_code_ix_queue != NULL) { /* unleash the entire herd */