Annotation of researchv9/jerq/sgs/inc/sdpsrc/hi/allocate.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * static char ID_allocc[] = "@(#) allocate.c: 1.1 1/7/82";
                      3:  */
                      4: 
                      5: ITEMID allocate(request, spacenbr, partnbr)
                      6: int request, spacenbr, partnbr;
                      7: {
                      8: 
                      9:        register HEADER *gframe;
                     10:        int framenbr;
                     11:        long pagenbr;
                     12:        long itemid;
                     13:        long getnxtpage();
                     14: 
                     15: /*
                     16:  * The request must be for an even number of bytes, and must hold an
                     17:  * itemid. No request can exceed one page
                     18:  */
                     19: 
                     20:        request = (request < ITEMIDSIZE) ? (ITEMIDSIZE) : ((request+1) & (~1));
                     21: 
                     22:        if( (request == 0)  ||  (request > PAGESIZE) )
                     23:                return( (ITEMID) fatal("allocate request out of range") );
                     24: 
                     25:        if( open_spacenumbers[spacenbr] != YES )
                     26:                return( (ITEMID) fatal("address space not yet opened") );
                     27: 
                     28:        if( (partnbr < 0)  ||  (partnbr > num_partitions) )
                     29:                return( (ITEMID) fatal("allocate partition out of range") );
                     30: 
                     31: 
                     32: /*
                     33:  * Satisfy the request. There are two cases:
                     34:  *
                     35:  *     1. Allocate a piece of the current page
                     36:  *     2. Allocate an entirely new page
                     37:  */
                     38: 
                     39:        gframe = &global_frames[spacenbr];
                     40: 
                     41: #if DEBUG
                     42:        if( dflag > 15 )
                     43:                fprintf( stderr, " alloc %04x %d %d ",
                     44:                        request, spacenbr, partnbr);
                     45: #endif
                     46:                
                     47:        if( gframe->curoffset + request <= PAGESIZE ) {
                     48: 
                     49:                itemid = BUILDPN(gframe->curpage, spacenbr) + gframe->curoffset;
                     50:                gframe->curoffset += request;
                     51: 
                     52:                return( (ITEMID) itemid );
                     53: 
                     54:                }
                     55:        
                     56:        if( (pagenbr = getnxtpage(spacenbr)) < 0 )
                     57:                return( (ITEMID) fatal("unable to allocate new page") );
                     58: 
                     59:        itemid = BUILDPN(pagenbr, spacenbr);
                     60: 
                     61:        if( (framenbr = sojourn(itemid, partnbr, NO)) < 0 )
                     62:                return( (ITEMID) fatal("unable to find frame for new page") );
                     63: 
                     64:        if( delist(framenbr) < 0 )
                     65:                return( (ITEMID) fatal("unable to delist frame of new page") );
                     66:        if( enlist(framenbr, MRU) < 0 )
                     67:                return( (ITEMID) fatal("unable to enlist frame of new page") );
                     68: 
                     69:        gframe->curpage = pagenbr;
                     70:        gframe->curoffset = request;
                     71: 
                     72:        return( (ITEMID) itemid );
                     73: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.