From: Matt Birkholz Date: Sat, 20 Dec 2014 21:34:56 +0000 (-0700) Subject: smp: share: uxfs.o X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=d4b4a9b877c4c58984d215e7796d420014f1654f;p=mit-scheme.git smp: share: uxfs.o --- diff --git a/README.txt b/README.txt index b6ededa62..5690b41df 100644 --- a/README.txt +++ b/README.txt @@ -683,8 +683,12 @@ command line. The remaining 12 belong to the 7 microcode modules and uxfile.o: uxfs.o: - 00000000 b directory_pointers - 00000004 b n_directory_pointers + 00000000 b directory_pointers locked + 00000004 b n_directory_pointers locked + + OK. The directory_pointers table is managed much like the + channel_table and is locked up in the same way. (Just the + writers are required to serialize.) uxio.o: 00000004 C OS_channel_table_size diff --git a/src/microcode/uxfs.c b/src/microcode/uxfs.c index 2f03cfd69..e56a67dc2 100644 --- a/src/microcode/uxfs.c +++ b/src/microcode/uxfs.c @@ -24,7 +24,7 @@ USA. */ -#include "scheme.h" +#include "prims.h" #include "ux.h" #include "osfs.h" #include "osfile.h" @@ -122,6 +122,13 @@ USA. #ifndef FILE_TOUCH_OPEN_TRIES # define FILE_TOUCH_OPEN_TRIES 5 #endif + +#ifdef ENABLE_SMP +static pthread_mutex_t mutex = MUTEX_INITIALIZER; +# ifdef ENABLE_DEBUGGING_TOOLS +static bool locked_p = false; +# endif +#endif #define STAT_SYSTEM_CALL(name, expression, if_failure) \ do { \ @@ -548,6 +555,7 @@ UX_initialize_directory_reader (void) static unsigned int allocate_directory_pointer (DIR * pointer) { + LOCK (); if (n_directory_pointers == 0) { DIR ** pointers = ((DIR **) (UX_malloc ((sizeof (DIR *)) * 4))); @@ -562,6 +570,7 @@ allocate_directory_pointer (DIR * pointer) while (scan < end) (*scan++) = 0; } + UNLOCK(); return (0); } { @@ -571,6 +580,7 @@ allocate_directory_pointer (DIR * pointer) if ((*scan++) == 0) { (*--scan) = pointer; + UNLOCK(); return (scan - directory_pointers); } } @@ -582,7 +592,10 @@ allocate_directory_pointer (DIR * pointer) (UX_realloc (((void *) directory_pointers), ((sizeof (DIR *)) * n_pointers)))); if (pointers == 0) - error_system_call (ENOMEM, syscall_realloc); + { + UNLOCK(); + error_system_call (ENOMEM, syscall_realloc); + } { DIR ** scan = (pointers + result); DIR ** end = (pointers + n_pointers); @@ -592,6 +605,7 @@ allocate_directory_pointer (DIR * pointer) } directory_pointers = pointers; n_directory_pointers = n_pointers; + UNLOCK(); return (result); } } @@ -643,6 +657,8 @@ OS_directory_read_matching (unsigned int index, const char * prefix) void OS_directory_close (unsigned int index) { + LOCK(); closedir (REFERENCE_DIRECTORY (index)); DEALLOCATE_DIRECTORY (index); + UNLOCK(); }