-
Notifications
You must be signed in to change notification settings - Fork 1
/
multi_threading.c
57 lines (50 loc) · 1.55 KB
/
multi_threading.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* multi_threading.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mghalmi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/28 10:48:32 by mghalmi #+# #+# */
/* Updated: 2024/02/07 15:48:54 by mghalmi ### ########.fr */
/* */
/* ************************************************************************** */
#include "main.h"
void *render_thread(void *ptr)
{
t_wrapper *w;
w = (t_wrapper *)ptr;
while (w->mlx.cam)
{
render_scene(&w);
w->mlx.cam = w->mlx.cam->next;
}
return (NULL);
}
void rendering(t_wrapper wrapper[NUM_THREADS])
{
pthread_t threads[NUM_THREADS];
int i;
i = 0;
while (i < NUM_THREADS)
{
pthread_create(&threads[i], NULL, render_thread, &wrapper[i]);
i++;
}
i = 0;
while (i < NUM_THREADS)
pthread_join(threads[i++], NULL);
}
void wrapp_data(t_mlx mlx, t_scene data, t_obj *lst, t_wrapper *wrapper)
{
int i;
i = 0;
while (i < NUM_THREADS)
{
wrapper[i].mlx = mlx;
wrapper[i].data = data;
wrapper[i].lst = lst;
wrapper[i].tid = i;
i++;
}
}