|
DataMuseum.dkPresents historical artifacts from the history of: Commodore CBM-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Commodore CBM-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - download
Length: 2465 (0x9a1) Types: TextFile Notes: UNIX file Names: »job.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code └─⟦2d53db1df⟧ UNIX Filesystem └─ ⟦this⟧ »hr/src/jlib/job.c«
#include <stdio.h> #include <job.h> #define SINC 16 /* stack growth increment */ struct jqueue runq; static struct jqueue idleq; static jmp_buf newstate; static *estack; extern char *malloc( ), *realloc( ); jmain( ) { int v, jidle( ); estack = &v; if (setjmp( newstate)) { (*my->j_startf)( ); jdone( ); } jstart( jidle); longjmp( newstate, not 0); } static jidle( ) { loop{ jdoze( &idleq); } } struct job * jstart( f) int (*f)( ); { struct job *jp; jp = malloc( sizeof *jp); if (not jp) nomem( ); jp->j_startf = f; jp->j_stack = 0; if (runq.jq_head) runq.jq_tail->j_next = jp; else runq.jq_head = jp; runq.jq_tail = jp; jp->j_next = 0; return (jp); } jdoze( jq) struct jqueue *jq; { register struct job *jp0, *jp1; uint n; int *sp; jalert( &idleq); jp0 = me; while (not jp0->j_next) readmesg( ); jp1 = jp0->j_next; if (jq->jq_head) jq->jq_tail->j_next = jp0; else jq->jq_head = jp0; jq->jq_tail = jp0; me = jp1; jp0->j_next = 0; if (setjmp( jp0->j_env)) return; sp = ((int **)jp0->j_env)[5]; /* not portable */ n = estack - sp; if (not jp0->j_stack) { jp0->j_smax = roundup( n, SINC); jp0->j_stack = malloc( jp0->j_smax*sizeof( *jp0->j_stack)); if (not jp0->j_stack) nomem( ); } else if (n > jp0->j_smax) { jp0->j_smax = roundup( n, SINC); jp0->j_stack = realloc( jp0->j_stack, jp0->j_smax*sizeof( *jp0->j_stack)); if (not jp0->j_stack) nomem( ); } copy( sp, n, jp0->j_stack); jp0->j_slength = n; if (not jp1->j_stack) longjmp( newstate, not 0); copygo( jp1->j_stack, jp1->j_slength, estack-jp1->j_slength); } jalert( jq) struct jqueue *jq; { struct job *jp; if (jp = jq->jq_head) { jq->jq_head = jp->j_next; if (runq.jq_head) runq.jq_tail->j_next = jp; else runq.jq_head = jp; runq.jq_tail = jp; jp->j_next = 0; return ~0; } return 0; } jdone( ) { struct job *jp; jalert( &idleq); while (not my->j_next) readmesg( ); jp = me; me = jp->j_next; if (jp->j_stack) free( (char *)jp->j_stack); free( (char *)jp); if (not my->j_stack) longjmp( newstate, not 0); copygo( my->j_stack, my->j_slength, estack-my->j_slength); } static copy( from, n, to) int *from, *to; uint n; { if (n) do { *to++ = *from++; } while (--n); } static copygo( from, n, to) int *from, *to; uint n; { char baggage[128]; if (baggage < to) { copy( from, n, to); longjmp( my->j_env, not 0); } copygo( from, n, to); }