AmendHub

Download:

jcs

/

subtext

/

amendments

/

40

uthread: Use panic()


jcs made amendment 40 over 2 years ago
--- uthread.c Sun Dec 12 13:07:13 2021 +++ uthread.c Sat Jan 1 20:21:47 2022 @@ -21,6 +21,7 @@ #include <setjmp.h> #include "uthread.h" +#include "util.h" #define STACK_SIZE (1024 * 4) #define CANARY 0xdeadf00d @@ -36,10 +37,8 @@ void uthread_init(void) { SetApplLimit(GetApplLimit() - (STACK_SIZE * (NUM_UTHREADS + 1))); - if (MemError()) { - SysBeep(20); - ExitToShell(); - } + if (MemError()) + panic("Failed to SetApplLimit"); } struct uthread * @@ -66,11 +65,8 @@ uthread_yield(void) { volatile long magic = CANARY; - if (uthread_current == NULL) { - printf("uthread_yield not from a thread!\n"); - ExitToShell(); - return; - } + if (uthread_current == NULL) + panic("uthread_yield not from a thread!"); if (uthread_current->state != UTHREAD_STATE_SLEEPING) uthread_current->state = UTHREAD_STATE_YIELDING; @@ -79,11 +75,8 @@ uthread_yield(void) longjmp(uthread_coord_env, UTHREAD_SETJMP_YIELDED); /* will not return */ - if (magic != CANARY) { - printf("canary clobbered!\n"); - SysBeep(20); - ExitToShell(); - } + if (magic != CANARY) + panic("canary clobbered!"); } void @@ -149,8 +142,7 @@ uthread_coordinate(void) case UTHREAD_SETJMP_YIELDED: break; default: - SysBeep(20); - ExitToShell(); + panic("unknown uthread state"); } }