From 0e6c77d9238939b6702d09bde24a596164549a21 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Wed, 27 May 2020 14:36:43 -0400 Subject: [PATCH] chore: align lifetimes for shortcuts --- runtime/src/current_sandbox.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/runtime/src/current_sandbox.c b/runtime/src/current_sandbox.c index 3338935..683a484 100644 --- a/runtime/src/current_sandbox.c +++ b/runtime/src/current_sandbox.c @@ -20,14 +20,18 @@ current_sandbox_get(void) void current_sandbox_set(struct sandbox *sandbox) { - // FIXME: critical-section. - worker_thread_current_sandbox = sandbox; - if (sandbox == NULL) return; - - // Thread Local State about the Current Sandbox - sandbox_lmbase = sandbox->linear_memory_start; - sandbox_lmbound = sandbox->linear_memory_size; - module_indirect_table = sandbox->module->indirect_table; + // Unpack hierarchy to avoid pointer chasing + if (sandbox == NULL) { + worker_thread_current_sandbox = NULL; + sandbox_lmbase = NULL; + sandbox_lmbound = 0; + module_indirect_table = NULL; + } else { + worker_thread_current_sandbox = sandbox; + sandbox_lmbase = sandbox->linear_memory_start; + sandbox_lmbound = sandbox->linear_memory_size; + module_indirect_table = sandbox->module->indirect_table; + } } /**