Пример #1
0
int sel4utils_reserve_range_no_alloc_aligned(vspace_t *vspace, sel4utils_res_t *reservation,
                                             size_t size, size_t size_bits, seL4_CapRights rights, int cacheable, void **result)
{
    sel4utils_alloc_data_t *data = get_alloc_data(vspace);
    void *vaddr = find_range(data, BYTES_TO_SIZE_BITS_PAGES(size, size_bits), size_bits);

    if (vaddr == NULL) {
        return -1;
    }

    *result = vaddr;
    reservation->malloced = 0;
    perform_reservation(vspace, reservation, (uintptr_t) vaddr, size, rights, cacheable);
    return 0;
}
void reservation(int sd) {
    int res;
    unsigned int seats_num = 0;

    //receive seats number
    res = read(sd,&seats_num,sizeof(seats_num));
    if(res < sizeof(seats_num)) {
        if(res == -1 ) {
            perror("receive number of seats");
        }
        else {
            puts("Error: received invalid seats num");
        }
        return;
    }
    if(alarm_flag == 1 ) {
        return;
    }

    //receive seats
    struct seat seats_temp[seats_num];
    res = read(sd,seats_temp,sizeof(seats_temp));
    if(res < sizeof(seats_temp)) {
        if(res == -1) {
            perror("receive seats");
        }
        else {
            puts("Error: mismatch of seats number recived");
        }
        return;
    }
    if(alarm_flag == 1 ) {
        return;
    }

    if (seats_available(seats_num,seats_temp) == 0 ||
            (check_constrains(seats_num,seats_temp) == -1) ||
            (no_double_seats(seats_temp,seats_num) == -1 ) ) {
        char msg[10] = "RES_ERR";
        res = send(sd,msg,11,0);
        if (res < 11 ) {
            perror("send error error");
            return;
        }
    }
    else {
        unsigned int last_res_index;
        struct reservation * r_entry;
        last_res_index = perform_reservation(seats_num,seats_temp,&r_entry);
        if ((save_reservation_array(info.rows*info.clmn,info.key_length)) == -1 ) {
            perform_delete(r_entry->reservation_code);
            return;
        }
        res = send(sd,r_entry->reservation_code,info.key_length+1,0);
        if (res < info.key_length+1) {
            puts("error sending reservation code");
            perform_delete(r_entry->reservation_code);
        }
    }
    return;
}