From 635b579ef297a121d5b9dac093e90d30a7c61832 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov <0x7fffff@guattari.ru> Date: Sun, 14 Aug 2022 05:05:10 +0400 Subject: test --- source/kit/thread.c | 45 ------------------------------------- source/kit/thread.h | 24 -------------------- source/test/unittests/thread.test.c | 18 --------------- 3 files changed, 87 deletions(-) delete mode 100644 source/kit/thread.c delete mode 100644 source/kit/thread.h delete mode 100644 source/test/unittests/thread.test.c (limited to 'source') diff --git a/source/kit/thread.c b/source/kit/thread.c deleted file mode 100644 index 66ff050..0000000 --- a/source/kit/thread.c +++ /dev/null @@ -1,45 +0,0 @@ -#include "thread.h" - -#ifdef _MSC_VER -# include "atomic.h" - -# include -# include - -typedef struct { - HANDLE thread; - kit_thread_routine_ routine; - void *user_data; - void *return_value; -} thread_data; - -DWORD __stdcall run_thread_(void *p) { - thread_data *data = (thread_data *) p; - data->return_value = data->routine(data->user_data); -} - -int pthread_create(pthread_t *new_thread, void *attrs, - kit_thread_routine_ routine, void *user_data) { - thread_data *data = (thread_data *) malloc(sizeof(thread_data)); - if (data == NULL) - return -1; - data->routine = routine; - data->user_data = user_data; - data->thread = CreateThread(NULL, 0, run_thread_, data, 0, NULL); - if (data->thread == NULL) - return -1; - if (new_thread != NULL) - *new_thread = data; - return 0; -} - -void *pthread_join(pthread_t thread, void *return_value) { - thread_data *data = (thread_data *) thread; - if (data == NULL || data->thread == NULL) - return (void *) 0; - WaitForSingleObject(data->thread, INFINITE); - void *return_value = data->return_value; - free(data); - return return_value; -} -#endif diff --git a/source/kit/thread.h b/source/kit/thread.h deleted file mode 100644 index 0fab0c8..0000000 --- a/source/kit/thread.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef KIT_THREAD_H -#define KIT_THREAD_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _MSC_VER -# include "pthread.h" -#else -typedef void *(*kit_thread_routine_)(void *); -typedef void *pthread_t; - -int pthread_create(pthread_t *new_thread, void *attrs, - kit_thread_routine_ routine, void *user_data); - -void *pthread_join(pthread_t thread, void *return_value); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/source/test/unittests/thread.test.c b/source/test/unittests/thread.test.c deleted file mode 100644 index fed564b..0000000 --- a/source/test/unittests/thread.test.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "../../kit/thread.h" - -#define KIT_TEST_FILE thread -#include "../../kit_test/test.h" - -static void *test_thread_fn(void *data) { - ptrdiff_t *value = (ptrdiff_t *) data; - return (void *) (*value + 20); -} - -TEST("run thread") { - pthread_t t; - ptrdiff_t value = 22; - pthread_create(&t, NULL, test_thread_fn, &value); - void *result; - pthread_join(t, &result); - REQUIRE((ptrdiff_t) result == 42); -} -- cgit v1.2.3