예제 #1
0
파일: philo.c 프로젝트: spuyet/philo
void		ft_state_change(int index, t_prgm *prgm, int state)
{
	if (state == EAT)
	{
		prgm->philo[index].life = MAX_LIFE;
		ft_put_state(prgm->philo + index, REST);
		pthread_mutex_unlock(prgm->wand + index);
		pthread_mutex_unlock(prgm->wand + ft_right(index));
	}
	else if (state == THINK)
	{
		if (pthread_mutex_trylock(prgm->wand + ft_right(index)) == 0)
			ft_put_state(prgm->philo + index, EAT);
	}
	else
	{
		if (prgm->philo[ft_left(index)].state == THINK
			|| prgm->philo[ft_right(index)].state == THINK
			|| pthread_mutex_trylock(prgm->wand + index))
			;
		else if (pthread_mutex_trylock(prgm->wand + ft_right(index)))
			ft_put_state(prgm->philo + index, THINK);
		else
			ft_put_state(prgm->philo + index, EAT);
	}
}
예제 #2
0
void		ft_while_main(int tab[4][4])
{
	int c;

	while ((c = getch()))
	{
		if (c == 27)
			break ;
		if (c == KEY_RIGHT)
			ft_down(tab);
		if (c == KEY_LEFT)
			ft_up(tab);
		if (c == KEY_UP)
			ft_left(tab);
		if (c == KEY_DOWN)
			ft_right(tab);
		if (!can_move(tab))
		{
			refresh();
			clear();
			printw("Can't move mother f****r");
			getch();
		}
		ft_aff_square(tab);
		if (!ft_aff_square(tab))
			printw("Window too small.\nThat's what she said.");
	}
}
예제 #3
0
파일: ft_event.c 프로젝트: kperreau/42
int			key_loop_hook(t_mlx *mx)
{
	if (mx->screen || mx->top || mx->bottom || mx->right || mx->left)
	{
		if (mx->screen)
			ft_tofile(mx->data);
		if (mx->top)
			ft_top(&mx->v, &mx->map);
		if (mx->bottom)
			ft_bottom(&mx->v, &mx->map);
		if (mx->left)
			ft_left(&mx->v);
		if (mx->right)
			ft_right(&mx->v);
		ft_display(mx, &mx->map, &mx->v);
	}
	return (0);
}
예제 #4
0
파일: ft_sh2.c 프로젝트: Erwanito/42sh
void	ft_sh2(t_line *tree, char ***newenv)
{
	int		fd[2];

	if (tree->type == 1)
		ft_execcmd(tree->cmd, newenv);
	if (tree->type == 2)
	{
		pipe(fd);
		ft_pipe(tree, newenv, fd);
	}
	if (tree->type == 3)
		ft_right(tree, newenv, 1);
	if (tree->type == 4)
		ft_left(tree, newenv);
	if (tree->type == 5)
		ft_right(tree, newenv, 2);
	if (tree->type == 7 || tree->type == 8)
		ft_logic_opp(tree, newenv);
}
예제 #5
0
파일: ft_amp.c 프로젝트: matt2905/Minishell
void			ft_amp(t_parser *parser, t_data *d)
{
	t_id		*tmp;
	t_id		*second;
	t_id		*first;

	tmp = d->child;
	ft_add_process(d, d->nb_process, ft_strdup(parser->left->str), fork());
	if (d->child == tmp)
		ft_left(parser, d);
	d->child->run = 1;
	first = d->child;
	if (parser->right)
	{
		ft_add_process(d, d->nb_process, ft_strdup(parser->right->str), fork());
		if (d->child == first)
			ft_right(parser, d);
		second = d->child;
		ft_printf("[%d]\t%d\n", d->child->nb, d->child->pid);
		waitpid(second->pid, &second->id, WUNTRACED);
		waitpid(second->pid, &second->id, WUNTRACED);
	}
}