コード例 #1
0
void		*f_rbtree_erase(t_rbtree *v_this, t_rbcell *node)
{
	t_rbcell	*j;
	t_rbcell	*i;
	void		*data;

	data = node->v_data;
	uf_rb_init_node(v_this, node, &j, &i);
	if (i->v_color == e_black)
		uf_rb_fix_node(v_this, j);
	if (i != node)
	{
		i->v_parent = node->v_parent;
		i->v_color = node->v_color;
		i->v_left = node->v_left;
		i->v_right = node->v_right;
		node->v_left->v_parent = i;
		node->v_right->v_parent = i;
		if (node == node->v_parent->v_left)
			node->v_parent->v_left = i;
		else
			node->v_parent->v_right = i;
	}
	uf_free_s((void **)&node);
	return (data);
}
コード例 #2
0
ファイル: s_unit_context.c プロジェクト: rclanget/42-toolkit
bool				mf_unit_add_test(t_unit *v_this, const char *context,
									const char *name,
									void (*test)(t_unit_test *))
{
	t_list_cell	*cell;
	t_unit_test	*t;

	cell = D_LIST(begin)(&v_this->v_context);
	while (cell != NULL)
	{
		if (uf_strcmp(context, ((t_unit_context*)cell->v_data)->v_name) == 0)
			break ;
		cell = cell->v_next;
	}
	if (cell == NULL)
		return (M_ERROR(false, "Could not find %s context", context));
	t = uf_unit_alloc_test(name, test);
	if (t == NULL)
		return (false);
	if (D_LIST(push_back)(&((t_unit_context*)cell->v_data)->v_test, t) == false)
	{
		uf_free_s((void **)&t);
		return (false);
	}
	return (true);
}
コード例 #3
0
ファイル: s_threadpool.c プロジェクト: rclanget/42-toolkit
static void	*f_threadpool_routine(void *arg)
{
	t_threadpool_data	*data;
	t_threadpool		*v_this;
	t_threadpool_task	*task;
	bool				run;

	run = true;
	v_this = (t_threadpool *)arg;
	while (run == true)
	{
		if (D_LOCK(lock)(&v_this->v_data, (void **)&data) == true)
		{
			run = data->v_run;
			task = D_QUEUE(pop)(&data->v_tasks);
			D_LOCK(release)(&v_this->v_data, (void **)&data);
			if (run == true && task != NULL)
			{
				task->f_funct(task->v_data);
				uf_free_s((void **)&task);
			}
		}
		usleep(5000);
	}
	return (NULL);
}
コード例 #4
0
ファイル: s_unit_context.c プロジェクト: rclanget/42-toolkit
static void			uf_unit_destroy_test(void *data)
{
	t_unit_test	*test;

	test = (t_unit_test *)data;
	D_LIST(destroy)(&test->v_assert);
	uf_free_s((void **)&data);
}
コード例 #5
0
ファイル: s_arqueue.c プロジェクト: QuentinPerez/42-toolkit
void		f_arqueue_destroy(t_arqueue *v_this)
{
	uf_free_s(&v_this->v_array);
	v_this->v_start = 0;
	v_this->v_end = 0;
	v_this->v_size = 0;
	v_this->v_capacity = 0;
	v_this->v_sizeof = 0;
	v_this->v_array = NULL;
}
コード例 #6
0
ファイル: s_threadpool.c プロジェクト: rclanget/42-toolkit
bool		f_threadpool_init(t_threadpool *v_this, size_t nb_thread)
{
	t_threadpool_data	*data;

	v_this->pv_data.v_run = false;
	if ((v_this->v_id = uf_malloc_s(nb_thread, sizeof(*v_this->v_id))) == NULL)
		return (M_ERROR(false, "Bad alloc"));
	D_QUEUE(init)(&v_this->pv_data.v_tasks, free);
	if (D_LOCK(init)(&v_this->v_data, &v_this->pv_data,
					e_lock_default) == false)
	{
		uf_free_s((void **)&v_this->v_id);
		return (M_ERROR(false, "Couldn't initialize lock"));
	}
	if (D_LOCK(lock)(&v_this->v_data, (void **)&data) == true)
		return (D_THREADPOOL(create)(v_this, data, nb_thread));
	D_LOCK(destroy)(&v_this->v_data);
	uf_free_s((void **)&v_this->v_id);
	return (M_ERROR(false, "An error has occured"));
}
コード例 #7
0
ファイル: s_stack.c プロジェクト: dannywillems/42-toolkit
void		f_stack_clear(t_stack *v_this)
{
	t_stack_cell	*del;

	while (v_this->v_last != NULL)
	{
		del = v_this->v_last;
		v_this->f_destroy(v_this->v_last->v_data);
		v_this->v_last = v_this->v_last->v_prev;
		uf_free_s((void **)&del);
	}
	v_this->v_size = 0;
}
コード例 #8
0
ファイル: s_threadpool.c プロジェクト: rclanget/42-toolkit
bool		f_threadpool_add_task(t_threadpool *v_this,
									t_threadpool_task *task)
{
	t_threadpool_task	*add;
	t_threadpool_data	*data;

	if ((add = uf_malloc_s(1, sizeof(*add))) == NULL)
		return (M_ERROR(false, "Bad alloc"));
	uf_memcpy(add, task, sizeof(*add));
	if (D_LOCK(lock)(&v_this->v_data, (void **)&data) == true)
	{
		if (D_QUEUE(push)(&data->v_tasks, add) == false)
		{
			uf_free_s((void **)&add);
			D_LOCK(release)(&v_this->v_data, (void **)&data);
			return (M_ERROR(false, "Couldn't add tasks"));
		}
		D_LOCK(release)(&v_this->v_data, (void **)&data);
		return (true);
	}
	uf_free_s((void **)&add);
	return (false);
}
コード例 #9
0
ファイル: s_list.c プロジェクト: dannywillems/42-toolkit
void		f_list_clear(t_list *v_this)
{
	t_list_cell	*cur;
	t_list_cell	*del;

	cur = v_this->v_begin;
	while (cur != NULL)
	{
		del = cur;
		cur = cur->v_next;
		v_this->f_destroy(del->v_data);
		uf_free_s((void **)&del);
	}
	D_LIST(init)(v_this, v_this->f_destroy);
}
コード例 #10
0
ファイル: s_queue.c プロジェクト: rclanget/42-toolkit
void		f_queue_clear(t_queue *v_this)
{
	t_queue_cell	*del;

	while (v_this->v_head != NULL)
	{
		del = v_this->v_head;
		v_this->f_destroy(del->v_data);
		v_this->v_head = del->v_next;
		uf_free_s((void **)&del);
	}
	v_this->v_tail = NULL;
	v_this->v_head = NULL;
	v_this->v_size = 0;
}
コード例 #11
0
ファイル: s_unit_context.c プロジェクト: rclanget/42-toolkit
bool				f_unit_add_context(t_unit *v_this, const char *name,
									bool (*init)(void *),
									bool (*destroy)(void *))
{
	t_unit_context	*context;

	if ((context = uf_malloc_s(1, sizeof(*context))) == NULL)
		return (M_ERROR(false, "Bad alloc"));
	context->v_name = name;
	context->f_init = init;
	context->f_destroy = destroy;
	context->v_id = D_LIST(size)(&v_this->v_context) + 1;
	D_LIST(init)(&context->v_test, uf_unit_destroy_test);
	if (D_LIST(push_back)(&v_this->v_context, context) == false)
	{
		uf_free_s((void **)&context);
		return (false);
	}
	return (true);
}
コード例 #12
0
ファイル: s_threadpool.c プロジェクト: rclanget/42-toolkit
void		f_threadpool_destroy(t_threadpool *v_this)
{
	size_t				i;
	t_threadpool_data	*data;

	i = 0;
	if (D_LOCK(lock)(&v_this->v_data, (void **)&data) == true)
	{
		data->v_run = false;
		D_LOCK(release)(&v_this->v_data, (void **)&data);
	}
	while (i < v_this->v_nb_thread)
	{
		if (pthread_join(v_this->v_id[i], NULL) != 0)
			M_INFOS("pthread_join error");
		i = i + 1;
	}
	D_LOCK(destroy)(&v_this->v_data);
	D_QUEUE(destroy)(&v_this->pv_data.v_tasks);
	uf_free_s((void **)&v_this->v_id);
}
コード例 #13
0
ファイル: s_array.c プロジェクト: sfroment/42-toolkit
void					f_array_destroy(t_array *v_this)
{
	D_ARRAY(clear)(v_this);
	uf_free_s((void **)&v_this->v_data);
	uf_memset(v_this, 0, sizeof(*v_this));
}
コード例 #14
0
ファイル: s_string.c プロジェクト: sfroment/42-toolkit
void					f_string_destroy(t_string *v_this)
{
	uf_free_s((void **)&v_this->v_str);
	uf_memset(v_this, 0, sizeof(*v_this));
}
コード例 #15
0
ファイル: s_arqueue.c プロジェクト: sfroment/42-toolkit
void		f_arqueue_destroy(t_arqueue *v_this)
{
	uf_free_s(&v_this->v_array);
}