From 0ea7f53216b7fdfbf5d97067e6e0fe0a707449c2 Mon Sep 17 00:00:00 2001 From: Matt Birkholz Date: Sat, 20 Dec 2014 12:08:15 -0700 Subject: [PATCH] Make storage.o state thread-local or single-threaded. Make the debugging flags and buffers pthread-local. Serialize use of the MAKE-EPHEMERON primitive with a pthread mutex. fixed_objects and heap_reserved are modified by primitives that the runtime system already uses in serial fashion. --- src/microcode/extern.h | 12 ++++++------ src/microcode/memmag.c | 9 +++++++++ src/microcode/storage.c | 12 ++++++------ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/microcode/extern.h b/src/microcode/extern.h index aeeca86c2..15e3c013d 100644 --- a/src/microcode/extern.h +++ b/src/microcode/extern.h @@ -114,12 +114,12 @@ extern void set_ulong_register (unsigned int, unsigned long); extern bool verify_heap (void); extern void Pop_Return_Break_Point (void); - extern unsigned int debug_slotno; - extern unsigned int debug_nslots; - extern unsigned int local_slotno; - extern unsigned int local_nslots; - extern unsigned int debug_circle []; - extern unsigned int local_circle []; + extern __thread unsigned int debug_slotno; + extern __thread unsigned int debug_nslots; + extern __thread unsigned int local_slotno; + extern __thread unsigned int local_nslots; + extern __thread unsigned int debug_circle []; + extern __thread unsigned int local_circle []; #else # define Eval_Debug 0 # define Hex_Input_Debug 0 diff --git a/src/microcode/memmag.c b/src/microcode/memmag.c index 963565e2b..e63ed9075 100644 --- a/src/microcode/memmag.c +++ b/src/microcode/memmag.c @@ -73,6 +73,10 @@ unsigned long saved_stack_size; #ifdef ENABLE_SMP int saved_processor_count; unsigned long saved_processor_heap_size; +static pthread_mutex_t mutex = MUTEX_INITIALIZER; +# ifdef ENABLE_DEBUGGING_TOOLS +static bool locked_p = false; +# endif #endif static gc_tospace_allocator_t allocate_tospace; @@ -715,6 +719,7 @@ compute_extra_ephemeron_space (unsigned long n) void guarantee_extra_ephemeron_space (unsigned long n) { + LOCK(); ephemeron_count = n; if (!ephemeron_array_big_enough_p (n)) { @@ -722,6 +727,7 @@ guarantee_extra_ephemeron_space (unsigned long n) assert (SHARED_HEAP_AVAILABLE_P (VECTOR_DATA + length)); ephemeron_array = make_ephemeron_vector (length); } + UNLOCK(); } static void @@ -741,6 +747,7 @@ gc_if_needed_for_ephemeron (unsigned long table_space) { n_ephemerons_requested = 1; ephemeron_request_hard_p = true; + UNLOCK(); Primitive_GC (EPHEMERON_SIZE); } #endif @@ -749,6 +756,7 @@ gc_if_needed_for_ephemeron (unsigned long table_space) DEFINE_PRIMITIVE ("MAKE-EPHEMERON", Prim_make_ephemeron, 2, 2, 0) { PRIMITIVE_HEADER (2); + LOCK(); ephemeron_count += 1; if (ephemeron_array_big_enough_p (ephemeron_count)) gc_if_needed_for_ephemeron (0); @@ -767,6 +775,7 @@ DEFINE_PRIMITIVE ("MAKE-EPHEMERON", Prim_make_ephemeron, 2, 2, 0) (*Free++) = SHARP_F; /* list */ (*Free++) = SHARP_F; /* queue */ assert ((Free - addr) == EPHEMERON_SIZE); + UNLOCK(); PRIMITIVE_RETURN (MAKE_POINTER_OBJECT (TC_EPHEMERON, addr)); } } diff --git a/src/microcode/storage.c b/src/microcode/storage.c index b15e596d3..469995ddd 100644 --- a/src/microcode/storage.c +++ b/src/microcode/storage.c @@ -135,12 +135,12 @@ bool ephemeron_request_hard_p; bool Trace_On_Error = false; bool Bignum_Debug = false; bool Per_File = false; - unsigned int debug_slotno = 0; - unsigned int debug_nslots = 0; - unsigned int local_slotno = 0; - unsigned int local_nslots = 0; - unsigned int debug_circle [100]; - unsigned int local_circle [100]; + __thread unsigned int debug_slotno = 0; + __thread unsigned int debug_nslots = 0; + __thread unsigned int local_slotno = 0; + __thread unsigned int local_nslots = 0; + __thread unsigned int debug_circle [100]; + __thread unsigned int local_circle [100]; #endif const char * CONT_PRINT_RETURN_MESSAGE = "SAVE_CONT, return code"; -- 2.25.1