From a21e8a31e8ee43f5f22f023e9bee8a58d1109500 Mon Sep 17 00:00:00 2001 From: Matt Birkholz Date: Fri, 5 Dec 2014 18:00:34 -0700 Subject: [PATCH] smp: share: uxenv.o --- README.txt | 14 ++++++++------ src/microcode/uxenv.c | 45 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/README.txt b/README.txt index 935db9c81..b6ededa62 100644 --- a/README.txt +++ b/README.txt @@ -671,12 +671,14 @@ command line. The remaining 12 belong to the 7 microcode modules and simultaneous threads can cause a ruckus, but otherwise... OK. uxenv.o: - 00000010 b current_dir_path - 0000000c b current_dir_path_size - 00000000 b initial_process_clock - 00000004 b initial_rtc - 00000000 d utc_epoch_minus_unix_epoch - 00000020 b zero_tx.8640 + 00000010 b current_dir_path locked + 0000000c b current_dir_path_size locked + 00000000 b initial_process_clock read-only, initialize_process_clock + 00000004 b initial_rtc read-only, initialize_real_time_clock + 00000000 d utc_epoch_minus_unix_epoch read-only + 00000020 b zero_tx.8640 read-only + + OK. uxfile.o: diff --git a/src/microcode/uxenv.c b/src/microcode/uxenv.c index 5ef35e0d3..d0c546fde 100644 --- a/src/microcode/uxenv.c +++ b/src/microcode/uxenv.c @@ -24,7 +24,6 @@ USA. */ -#include "scheme.h" #include "prims.h" #include "ux.h" #include "osenv.h" @@ -622,25 +621,45 @@ UX_initialize_environment (void) static size_t current_dir_path_size = 0; static char * current_dir_path = 0; +#ifdef ENABLE_SMP +static pthread_mutex_t mutex = MUTEX_INITIALIZER; +# ifdef ENABLE_DEBUGGING_TOOLS +static bool locked_p = false; +# endif +#endif + const char * OS_working_dir_pathname (void) { - if (current_dir_path) { - return (current_dir_path); - } + LOCK(); + if (current_dir_path) + { + char *p = current_dir_path; + UNLOCK(); + return (p); + } if (current_dir_path_size == 0) { current_dir_path = (UX_malloc (1024)); if (current_dir_path == 0) - error_system_call (ENOMEM, syscall_malloc); + { + UNLOCK(); + error_system_call (ENOMEM, syscall_malloc); + } current_dir_path_size = 1024; } while (1) { if ((UX_getcwd (current_dir_path, current_dir_path_size)) != 0) - return (current_dir_path); + { + UNLOCK(); + return (current_dir_path); + } if (errno != ERANGE) - error_system_call (errno, syscall_getcwd); + { + UNLOCK(); + error_system_call (errno, syscall_getcwd); + } current_dir_path_size *= 2; { char * new_current_dir_path = @@ -648,7 +667,10 @@ OS_working_dir_pathname (void) if (new_current_dir_path == 0) /* ANSI C requires `path' to be unchanged -- we may have to discard it for systems that don't behave thus. */ - error_system_call (ENOMEM, syscall_realloc); + { + UNLOCK(); + error_system_call (ENOMEM, syscall_realloc); + } current_dir_path = new_current_dir_path; } } @@ -658,10 +680,12 @@ void OS_set_working_dir_pathname (const char * name) { size_t name_size = strlen (name); + LOCK(); STD_VOID_SYSTEM_CALL (syscall_chdir, (UX_chdir (name))); while (1) { if (name_size < current_dir_path_size) { strcpy(current_dir_path, name); + UNLOCK(); return; } current_dir_path_size *= 2; @@ -669,7 +693,10 @@ OS_set_working_dir_pathname (const char * name) char * new_current_dir_path = (UX_realloc (current_dir_path, current_dir_path_size)); if (new_current_dir_path == 0) - error_system_call (ENOMEM, syscall_realloc); + { + UNLOCK(); + error_system_call (ENOMEM, syscall_realloc); + } current_dir_path = new_current_dir_path; } } -- 2.25.1