Switch back to pthread.h

fix-mingw
Nakidai 2023-11-24 23:32:42 +03:00
parent 0b74ef8618
commit ce1e91d90f
3 changed files with 7 additions and 7 deletions

View File

@ -9,6 +9,6 @@ typedef struct input_args_t
bool *alive; bool *alive;
} InputArgs; } InputArgs;
int input(void *vargp); void *input(void *vargp);
#endif /* __INPUT_H__ */ #endif /* __INPUT_H__ */

View File

@ -30,7 +30,7 @@ int getch(void)
} }
#endif #endif
int input(void *vargp) void *input(void *vargp)
{ {
int *out = ((InputArgs *)vargp)->out; int *out = ((InputArgs *)vargp)->out;
bool *alive = ((InputArgs *)vargp)->alive; bool *alive = ((InputArgs *)vargp)->alive;
@ -39,5 +39,5 @@ int input(void *vargp)
{ {
*out = getch(); *out = getch();
} }
return 0; return NULL;
} }

View File

@ -1,7 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <threads.h> #include <pthread.h>
#include <time.h> #include <time.h>
#include "input.h" #include "input.h"
@ -38,7 +38,7 @@ int main(int argc, char **argv)
Player *player = playerCreate(DOWN, DEFX, DEFY, 0); Player *player = playerCreate(DOWN, DEFX, DEFY, 0);
Screen *screen = screenCreate(SIZE, SIZE, ' '); Screen *screen = screenCreate(SIZE, SIZE, ' ');
PlayerNode *node; PlayerNode *node;
thrd_t input_thread; pthread_t input_thread;
int i; int i;
int head_x, head_y; int head_x, head_y;
Food food = generateFood(player); Food food = generateFood(player);
@ -48,7 +48,7 @@ int main(int argc, char **argv)
bool stopped = false; bool stopped = false;
InputArgs input_args = (InputArgs){ key, running }; InputArgs input_args = (InputArgs){ key, running };
thrd_create(&input_thread, input, &input_args); pthread_create(&input_thread, NULL, input, &input_args);
while (*running) while (*running)
{ {
screenSet(screen, ' '); screenSet(screen, ' ');
@ -59,7 +59,7 @@ int main(int argc, char **argv)
for (i = 0; i < SIZE*2; ++i) putchar('-'); for (i = 0; i < SIZE*2; ++i) putchar('-');
printf("\nScore: %d\n", player->score); printf("\nScore: %d\n", player->score);
thrd_sleep(&(struct timespec){.tv_sec=1}, NULL); nanosleep(&(struct timespec){.tv_sec = 1}, NULL);
switch (*key) switch (*key)
{ {
case 'q': case 'q':