Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thread: use pthread as default fallback #354

Merged
merged 4 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -401,6 +401,8 @@ set(SRCS

src/telev/telev.c

src/thread/thread.c

src/tmr/tmr.c

src/trace/trace.c
Expand Down Expand Up @@ -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")
Expand Down
22 changes: 9 additions & 13 deletions include/re_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -18,17 +18,7 @@

#else

#if defined(HAVE_PTHREAD)

#include <pthread.h>
#include <time.h>
#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 <windows.h>
#define ONCE_FLAG_INIT INIT_ONCE_STATIC_INIT
Expand All @@ -39,7 +29,13 @@ typedef CRITICAL_SECTION mtx_t;

#else

#error "thread: system not supported"
#include <pthread.h>
#include <time.h>
#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

Expand Down
8 changes: 3 additions & 5 deletions src/thread/mod.mk
Original file line number Diff line number Diff line change
@@ -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