Пример #1
0
int db_free(db_t db, size_t n) {
    long base;
    base = db;
    demand(!db_isfree(base, n), Blocks not allocated.);
    Bit_clear(free_map, base, base + n - 1);
    return base;
}
Пример #2
0
/* puts each element into bit vector to check digits */
void check_setof9(int col, int row, UArray2_T a, void *elem, void *bit) 
{  
        int digit  = *(int *)elem; 
        Bit_T b = bit;        
        
        if (digit < 1 || digit > 9) {
                Bit_free(&b);     
                UArray2_free(&a);
                exit(1);
        /* digit is already in vector */
        } if (Bit_get(bit, digit) == 1) {
                Bit_free(&b);  
                UArray2_free(&a);
                exit(1);
        /* if digit isn't in vector, change bit to 1 */
        } else {
                Bit_put(bit, digit, 1);
        /*all nine digits are present, reset bit vector*/
        } if (Bit_count(bit) == 9) {
                Bit_clear(bit, 1, 9);
        }

        (void) col;
        (void) row;
        (void) a;
}
Пример #3
0
void kernel_init(void) {
    static int init;

    pmap_start = 1;
    if(init) {
        Bit_clear(free_map, 0, XN_NBLOCKS-1);
        return;
    }
    init = 1;
    pages = (void *)malloc(XN_BLOCK_SIZE * (PHYS_MEM+1));
    assert(pages);
    pages = (void *)roundup((unsigned)pages, XN_BLOCK_SIZE);
    demand((unsigned) pages % XN_BLOCK_SIZE == 0, Bogus alignment);

    pmap = Bit_new(PHYS_MEM);
    free_map = Bit_new(XN_NBLOCKS);
    demand(db_isfree(0, 1), should have allocated);
    db_alloc(0, 1);
    demand(!db_isfree(0, 1), should have allocated);
}
Пример #4
0
void pfree(ppn_t base, size_t npages) {
    printf("freeing [%ld, %ld)\n", base, base + npages);
    demand(!Bit_off(pmap, base, base + npages), pages not allocated.);
    Bit_clear(pmap, base, base + npages - 1);
}