diff --git a/CMakeLists.txt b/CMakeLists.txt index 48073ba1b..d6c0809d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,7 @@ include(GNUInstallDirs) include(CheckIncludeFile) include(CheckFunctionExists) find_package(Backtrace) -find_package(Threads) +find_package(Threads REQUIRED) find_package(OpenSSL) check_symbol_exists("arc4random" "stdlib.h" HAVE_ARC4RANDOM) @@ -401,6 +401,8 @@ set(SRCS src/telev/telev.c + src/thread/thread.c + src/tmr/tmr.c src/trace/trace.c @@ -550,19 +552,15 @@ elseif(HAVE_PTHREAD) endif() if(HAVE_THREADS) + #Do nothing +elseif(CMAKE_USE_WIN32_THREADS_INIT) list(APPEND SRCS - src/thread/thread.c + src/thread/win32.c ) -elseif(HAVE_PTHREAD) +else() list(APPEND SRCS - src/thread/thread.c src/thread/posix.c ) -elseif(CMAKE_USE_WIN32_THREADS_INIT) - list(APPEND SRCS - src/thread/thread.c - src/thread/win32.c - ) endif() if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") diff --git a/include/re_thread.h b/include/re_thread.h index d98234ab8..1fbc96c09 100644 --- a/include/re_thread.h +++ b/include/re_thread.h @@ -7,8 +7,8 @@ * Preferred order: * * - C11 threads (glibc>=2.28, musl, FreeBSD>=10) - * - POSIX PTHREAD (Linux/UNIX, winpthreads) * - Windows Thread API + * - POSIX PTHREAD (Linux/UNIX) * * Copyright (C) 2022 Sebastian Reimers */ @@ -18,17 +18,7 @@ #else -#if defined(HAVE_PTHREAD) - -#include -#include -#define ONCE_FLAG_INIT PTHREAD_ONCE_INIT -typedef pthread_once_t once_flag; -typedef pthread_t thrd_t; -typedef pthread_cond_t cnd_t; -typedef pthread_mutex_t mtx_t; - -#elif defined(WIN32) +#if defined(WIN32) #include #define ONCE_FLAG_INIT INIT_ONCE_STATIC_INIT @@ -39,7 +29,13 @@ typedef CRITICAL_SECTION mtx_t; #else -#error "thread: system not supported" +#include +#include +#define ONCE_FLAG_INIT PTHREAD_ONCE_INIT +typedef pthread_once_t once_flag; +typedef pthread_t thrd_t; +typedef pthread_cond_t cnd_t; +typedef pthread_mutex_t mtx_t; #endif diff --git a/src/thread/mod.mk b/src/thread/mod.mk index 59ae74292..9028fcd05 100644 --- a/src/thread/mod.mk +++ b/src/thread/mod.mk @@ -1,9 +1,7 @@ ifdef HAVE_THREADS -SRCS += thread/thread.c -else ifdef HAVE_PTHREAD -SRCS += thread/thread.c -SRCS += thread/posix.c else ifeq ($(OS),win32) -SRCS += thread/thread.c SRCS += thread/win32.c +else +SRCS += thread/posix.c endif +SRCS += thread/thread.c