diff options
Diffstat (limited to 'src/threads/init.c')
| -rw-r--r-- | src/threads/init.c | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/src/threads/init.c b/src/threads/init.c index 43f491f..6633d2c 100644 --- a/src/threads/init.c +++ b/src/threads/init.c @@ -48,11 +48,20 @@ static bool format_filesys; /* -q: Power off after kernel tasks complete? */ bool power_off_when_done = false; -/* -Q: Force power off by klaar@ida... */ + +/* Options by klaar@ida */ + +/* -Q: Force power off */ bool force_off_when_done = false; -/* -tcf: Simulate failure in thread_create klaar@ida... */ +/* -F: Set timer frequency */ +static uint16_t init_timer_freq = 1000; +/* -tcf: Simulate failure in thread_create */ int thread_create_limit = 0; /* infinite */ +static bool prevent_reqursive_off = false; + +static void hard_power_off (void) NO_RETURN; + static void ram_init (void); static void paging_init (void); @@ -101,7 +110,7 @@ main (void) /* Initialize interrupt handlers. */ intr_init (); - timer_init (); + timer_init (init_timer_freq); kbd_init (); input_init (); #ifdef USERPROG @@ -244,6 +253,8 @@ parse_options (char **argv) power_off_when_done = true; else if (!strcmp (name, "-Q")) // klaar@ida power_off_when_done = force_off_when_done = true; + else if (!strcmp (name, "-F")) // klaar@ida + init_timer_freq = atoi (value); #ifdef FILESYS else if (!strcmp (name, "-f")) format_filesys = true; @@ -369,24 +380,20 @@ usage (void) #endif ); - /* klaar@ida disabled due to threads and locks not initialized + /* klaar@ida changed due to threads and locks not initialized * yet... and power_off() now use locks. */ -// power_off (); + hard_power_off (); } - /* Powers down the machine we're running on, as long as we're running on Bochs or QEMU. */ -void -power_off (void) +static void +hard_power_off (void) { const char s[] = "Shutdown"; const char *p; - printf ("# Preparing to power off...\n"); - DEBUG_thread_poweroff_check( force_off_when_done ); - #ifdef FILESYS filesys_done (); #endif @@ -412,6 +419,22 @@ power_off (void) for (;;); } +/* Powers down the machine we're running on, + as long as we're running on Bochs or QEMU. */ +void +power_off (void) +{ + if ( prevent_reqursive_off ) + hard_power_off (); + + prevent_reqursive_off = true; + + printf ("# Preparing to power off...\n"); + DEBUG_thread_poweroff_check( force_off_when_done ); + + hard_power_off (); +} + /* Print statistics about Pintos execution. */ static void print_stats (void) |
