示例#1
0
// Initialize the buffer-cache in a shared memory block
buffcach *bc_ini() {
    int i, j;

    // avoid debugging file on init
    dbm = 0;

    // ensure key files existence
    close(creat(_SHMKEYPATH_BC_, 0666));
    close(creat(_SEMKEYPATH_BC_, 0666));

    // allocate buffer-cache in shared memory
    bc = (buffcach *)shmalloc(&bcshmid, _SHMKEY_BC_, _SIZE_BC_, 1);

    // initialize free list
    bc->header.freestart = 0;
    bc->header.freeend = MAXBUFF - 1;

    // initialize hash list
    for (i = 0; i < MAXHASH; i++)
        bc->header.hash[i] = -1;

    // initialize slept list
    for (i = 0; i < MAXSLPT; i++)
        bc->header.slept[i] = -1;

    // initialize buffers and link free list nodes
    for (i = 0; i < MAXBUFF; i++) {
        BS_CLR(bc->buffers[i].status, BS_LOCKED);
        BS_CLR(bc->buffers[i].status, BS_VALID);
        BS_CLR(bc->buffers[i].status, BS_DELAYED);

        if (i > 0)
            bc->buffers[i].freeprev = i - 1;

        if (i < MAXBUFF - 1)
            bc->buffers[i].freenext = i + 1;

        bc->buffers[i].hashnext = -1;

        for (j = 0; j < MAXSLPT; j++)
            bc->buffers[i].slept[j] = -1;
    }

    bc->buffers[0].freeprev = -1;
    bc->buffers[MAXBUFF - 1].freenext = -1;

    // initialize mutex semaphore
    semid = semInit(_SEMKEY_BC_, (short)1);

    // initialize files table
    ft_ini();

    // return initialized buffer-cache structure
    return bc;
}
示例#2
0
文件: main.c 项目: apellicc/fdf
int		main(int argc, char **argv)
{
	t_en	e;

	if (argc != 2)
		ft_putendl("error");
	if (argc != 2)
		return (0);
	ft_ini(&e);
	ft_parse(argv[1], &e);
	draw(&e);
//	mlx_put_image_to_window(e.mlx, e.win_para, e.img_para, 0, 0);
	mlx_hook(e.win_para, 2, 3, key, &e);
	mlx_hook(e.win_iso, 2, 3, key, &e);
	mlx_loop_hook(e.mlx, (void *)draw, &e);
	mlx_loop(e.mlx);
	return (0);
}