From 015b989a66c889b8496ed396ebd2cd6321070449 Mon Sep 17 00:00:00 2001 From: Geoffrey Challen Date: Thu, 31 Dec 2015 19:38:38 -0500 Subject: [PATCH] Fixing synchronization tests. --- kern/conf/BASE | 33 ----------------------- kern/include/synchprobs.h | 6 ++--- kern/synchprobs/stoplight.c | 6 ++--- kern/test/synchprobs.c | 53 +++++++++++++++++++++---------------- 4 files changed, 36 insertions(+), 62 deletions(-) delete mode 100644 kern/conf/BASE diff --git a/kern/conf/BASE b/kern/conf/BASE deleted file mode 100644 index 3216e1f..0000000 --- a/kern/conf/BASE +++ /dev/null @@ -1,33 +0,0 @@ -# Kernel config file using dumbvm. -# This should be used until you have your own VM system. - -include conf/conf.kern # get definitions of available options - -debug # Compile with debug info. - -# -# Device drivers for hardware. -# -device lamebus0 # System/161 main bus -device emu* at lamebus* # Emulator passthrough filesystem -device ltrace* at lamebus* # trace161 trace control device -device ltimer* at lamebus* # Timer device -device lrandom* at lamebus* # Random device -device lhd* at lamebus* # Disk device -device lser* at lamebus* # Serial port -#device lscreen* at lamebus* # Text screen (not supported yet) -#device lnet* at lamebus* # Network interface (not supported yet) -device beep0 at ltimer* # Abstract beep handler device -device con0 at lser* # Abstract console on serial port -#device con0 at lscreen* # Abstract console on screen (not supported) -device rtclock0 at ltimer* # Abstract realtime clock -device random0 at lrandom* # Abstract randomness device - -#options net # Network stack (not supported) -options semfs # Semaphores for userland - -options sfs # Always use the file system -#options netfs # You might write this as a project. - -options dumbvm # Chewing gum and baling wire. -#options synchprobs # Uncomment to enable ASST1 synchronization problems diff --git a/kern/include/synchprobs.h b/kern/include/synchprobs.h index 30fd03a..1f87846 100644 --- a/kern/include/synchprobs.h +++ b/kern/include/synchprobs.h @@ -19,9 +19,9 @@ void matchmaker(void); * stoplight.c. */ -void gostraight(unsigned long); -void turnleft(unsigned long); -void turnright(unsigned long); +void gostraight(uint32_t); +void turnleft(uint32_t); +void turnright(uint32_t); void stoplight_init(void); void stoplight_cleanup(void); diff --git a/kern/synchprobs/stoplight.c b/kern/synchprobs/stoplight.c index 33f57d7..e511f79 100644 --- a/kern/synchprobs/stoplight.c +++ b/kern/synchprobs/stoplight.c @@ -85,7 +85,7 @@ void stoplight_cleanup() { } void -turnright(unsigned long direction) +turnright(uint32_t direction) { (void)direction; /* @@ -94,7 +94,7 @@ turnright(unsigned long direction) return; } void -gostraight(unsigned long direction) +gostraight(uint32_t direction) { (void)direction; /* @@ -103,7 +103,7 @@ gostraight(unsigned long direction) return; } void -turnleft(unsigned long direction) +turnleft(uint32_t direction) { (void)direction; /* diff --git a/kern/test/synchprobs.c b/kern/test/synchprobs.c index 374dc94..ae63395 100644 --- a/kern/test/synchprobs.c +++ b/kern/test/synchprobs.c @@ -20,15 +20,22 @@ * Shared initialization routines */ -static struct semaphore *testsem; +static struct semaphore *startsem; +static struct semaphore *endsem; static void inititems(void) { - if (testsem==NULL) { - testsem = sem_create("testsem", 0); - if (testsem == NULL) { + if (startsem==NULL) { + startsem = sem_create("startsem", 0); + if (startsem == NULL) { + panic("synchprobs: sem_create failed\n"); + } + } + if (endsem==NULL) { + endsem = sem_create("endsem", 0); + if (endsem == NULL) { panic("synchprobs: sem_create failed\n"); } } @@ -45,9 +52,9 @@ male_wrapper(void * unused1, unsigned long unused2) { (void)unused2; random_yielder(4); - P(testsem); + P(startsem); male(); - V(testsem); + V(endsem); return; } @@ -69,9 +76,9 @@ female_wrapper(void * unused1, unsigned long unused2) { (void)unused2; random_yielder(4); - P(testsem); + P(startsem); female(); - V(testsem); + V(endsem); return; } @@ -93,9 +100,9 @@ matchmaker_wrapper(void * unused1, unsigned long unused2) { (void)unused2; random_yielder(4); - P(testsem); + P(startsem); matchmaker(); - V(testsem); + V(endsem); return; } @@ -147,13 +154,13 @@ whalemating(int nargs, char **args) { for (i = 0; i < 3; i++) { for (j = 0; j < NMATING; j++) { - V(testsem); + V(startsem); } } for (i = 0; i < 3; i++) { for (j = 0; j < NMATING; j++) { - P(testsem); + P(endsem); } } @@ -173,9 +180,9 @@ turnright_wrapper(void *unused, unsigned long direction) (void)unused; random_yielder(4); - P(testsem); - turnright(direction); - V(testsem); + P(startsem); + turnright((uint32_t)direction); + V(endsem); return; } @@ -186,9 +193,9 @@ gostraight_wrapper(void *unused, unsigned long direction) (void)unused; random_yielder(4); - P(testsem); - gostraight(direction); - V(testsem); + P(startsem); + gostraight((uint32_t)direction); + V(endsem); return; } @@ -199,9 +206,9 @@ turnleft_wrapper(void *unused, unsigned long direction) (void)unused; random_yielder(4); - P(testsem); - turnleft(direction); - V(testsem); + P(startsem); + turnleft((uint32_t)direction); + V(endsem); return; } @@ -255,11 +262,11 @@ int stoplight(int nargs, char **args) { } for (i = 0; i < NCARS; i++) { - V(testsem); + V(startsem); } for (i = 0; i < NCARS; i++) { - P(testsem); + P(endsem); } stoplight_cleanup();