コード例 #1
0
ファイル: ptable.c プロジェクト: garlik/4store
int fs_ptable_close(fs_ptable *pt)
{
    if (!pt) return 1;

    unmap_pt(pt);
    close(pt->fd);
    g_free(pt->filename);
    pt->filename = NULL;
    pt->fd = -1;
    free(pt);

    return 0;
}
コード例 #2
0
ファイル: ptable.c プロジェクト: 66laps/4store
fs_row_id fs_ptable_new_row(fs_ptable *pt)
{
    if (!pt->ptr) {
        fs_error(LOG_CRIT, "attempted to get row from unmapped ptable");

        return 0;
    }
    if (pt->header->length == 0) {
        pt->header->length = 1;
    }

    /* we can reuse a free'd row */
    if (pt->header->free_list) {
        fs_row_id newr = pt->header->free_list;
        row *r = &pt->data[newr];
        pt->header->free_list = r->cont;
        r->cont = 0;
        r->data[0] = 0;
        r->data[1] = 0;

        return newr;
    }
        
    if (pt->header->length >= pt->header->size) {
        int length = pt->header->length;
        int size = pt->header->size;
        unmap_pt(pt);
        map_pt(pt, length, size * 2);
    }

    row *r = &pt->data[pt->header->length];
    r->cont = 0;
    r->data[0] = 0;
    r->data[1] = 0;

    return (pt->header->length)++;
}