aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_sfx_trap.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-16 19:41:26 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-16 19:41:26 +0100
commita8c9c04ec24a71f076891bdc1c26860db7c5c9c3 (patch)
treea5dc6905f6987c4d5fcd27276f7fc338f2af8f0b /src/ft_sfx_trap.c
parentCleaner memdels (diff)
parentMerge branch 'master' into back-to-pthread (diff)
download42-cub3d-a8c9c04ec24a71f076891bdc1c26860db7c5c9c3.tar.gz
42-cub3d-a8c9c04ec24a71f076891bdc1c26860db7c5c9c3.tar.bz2
42-cub3d-a8c9c04ec24a71f076891bdc1c26860db7c5c9c3.tar.xz
42-cub3d-a8c9c04ec24a71f076891bdc1c26860db7c5c9c3.tar.zst
42-cub3d-a8c9c04ec24a71f076891bdc1c26860db7c5c9c3.zip
Merge branch 'back-to-pthread'
Diffstat (limited to 'src/ft_sfx_trap.c')
-rw-r--r--src/ft_sfx_trap.c41
1 files changed, 16 insertions, 25 deletions
diff --git a/src/ft_sfx_trap.c b/src/ft_sfx_trap.c
index 1499ecf..d55dd57 100644
--- a/src/ft_sfx_trap.c
+++ b/src/ft_sfx_trap.c
@@ -10,40 +10,31 @@
/* */
/* ************************************************************************** */
-#include <libft.h>
#include <cub3d.h>
-#include <unistd.h>
-#include <stdint.h>
+#include <stdlib.h>
+#include <pthread.h>
-static void
- ft_sfx_pain(t_cub *cl)
+void
+ *ft_sfx_trap_thread(void *vargp)
{
- static uint8_t ref = 0;
+ t_sfx *sfx;
- ref += 1;
- if (ref > 201)
- ref = 0;
- if (ref % 2)
+ if (FT_OS == 1)
+ pthread_setcancelstate(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+ else
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+ sfx = (t_sfx *)vargp;
+ pthread_mutex_lock(&sfx->trap_mutex);
+ while (1)
{
- cl->sfx.pain_pid = fork();
- if (cl->sfx.pain_pid == 0)
- {
- if (ref % 3)
- execve(*(cl->sfx.pain_one + 0), cl->sfx.pain_one, cl->envp);
- else
- execve(*(cl->sfx.pain_two + 0), cl->sfx.pain_two, cl->envp);
- }
+ pthread_mutex_lock(&sfx->trap_mutex);
+ system(sfx->trap);
}
+ return (NULL);
}
void
ft_sfx_trap(t_cub *cl)
{
- cl->sfx.trap_pid = fork();
- if (cl->sfx.trap_pid == 0)
- execve(*(cl->sfx.trap + 0), cl->sfx.trap, cl->envp);
- else
- {
- ft_sfx_pain(cl);
- }
+ pthread_mutex_unlock(&cl->sfx.trap_mutex);
}