diff options
| author | Mikhail Romanko <me@blankhex.com> | 2024-06-12 12:09:59 +0300 |
|---|---|---|
| committer | Mikhail Romanko <me@blankhex.com> | 2024-06-12 12:09:59 +0300 |
| commit | bfa33b377872d3fb7aa471e8a0af3382081971f3 (patch) | |
| tree | e695411f7541055b3238c76e709a7416980c7202 | |
| parent | 5762484550ddf65c7d26515211534e200ec79536 (diff) | |
| download | bhlib-old-bfa33b377872d3fb7aa471e8a0af3382081971f3.tar.gz | |
Add internal configuration file, add missing includes, rename some options
| -rw-r--r-- | CMakeLists.txt | 21 | ||||
| -rw-r--r-- | include/bh/buffer.h | 1 | ||||
| -rw-r--r-- | include/bh/config.in | 4 | ||||
| -rw-r--r-- | include/bh/deflate.h | 1 | ||||
| -rw-r--r-- | include/bh/file.h | 1 | ||||
| -rw-r--r-- | include/bh/internal/bh.h | 7 | ||||
| -rw-r--r-- | include/bh/internal/buffer.h | 1 | ||||
| -rw-r--r-- | include/bh/internal/config.in | 6 | ||||
| -rw-r--r-- | include/bh/internal/file.h | 1 | ||||
| -rw-r--r-- | include/bh/internal/hashmap.h | 1 | ||||
| -rw-r--r-- | include/bh/internal/io.h | 1 | ||||
| -rw-r--r-- | include/bh/internal/queue.h | 1 | ||||
| -rw-r--r-- | include/bh/internal/thread.h | 5 | ||||
| -rw-r--r-- | include/bh/thread.h | 11 | ||||
| -rw-r--r-- | src/thread_win.c | 2 |
15 files changed, 47 insertions, 17 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c84cd4b..086f166 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,9 @@ include(CheckIPOSupported) include(CheckIncludeFile) include(CheckSymbolExists) +# Project settings +option(BH_PLATFORM_THREADS "Enable multithreading support" TRUE) + # Check for IPO/LTO check_ipo_supported(RESULT supported) @@ -55,6 +58,7 @@ set(BH_INCLUDE_DIRS if(WIN32) message(STATUS "Platform - Win32") set(BH_PLATFORM_WIN TRUE) + option(BH_THREADS_WINXP "Enable threading support for Windows XP" FALSE) # Add platform dependent files list(APPEND BH_SOURCE @@ -62,8 +66,11 @@ if(WIN32) ) # Check multithreading support - check_symbol_exists(_beginthread process.h BH_USE_WINTHREAD) - if(BH_USE_WINTHREAD) + if(BH_PLATFORM_THREADS) + check_symbol_exists(_beginthread process.h BH_PLATFORM_THREADS) + endif() + + if(BH_PLATFORM_THREADS) message(STATUS "Multithreading enabled") list(APPEND BH_SOURCE src/thread_win.c @@ -75,7 +82,7 @@ if(WIN32) ) endif() - if(BH_NO_WINXP) + if(NOT BH_THREADS_WINXP) add_definitions(-D_WIN32_WINNT=_WIN32_WINNT_VISTA -DWINVER=_WIN32_WINNT_VISTA) endif() elseif(UNIX) @@ -88,8 +95,11 @@ elseif(UNIX) ) # Check multithreading support - check_include_file(pthread.h BH_USE_PTHREAD) - if(BH_USE_PTHREAD) + if(BH_PLATFORM_THREADS) + check_include_file(pthread.h BH_PLATFORM_THREADS) + endif() + + if(BH_PLATFORM_THREADS) message(STATUS "Multithreading enabled") list(APPEND BH_SOURCE src/thread_posix.c @@ -111,6 +121,7 @@ endif() # Configure library configure_file(include/bh/config.in include/bh/config.h) +configure_file(include/bh/internal/config.in include/bh/internal/config.h) # Library add_library(bhlib STATIC ${BH_SOURCE} ${BH_HEADER}) diff --git a/include/bh/buffer.h b/include/bh/buffer.h index 35c89cc..b3a891f 100644 --- a/include/bh/buffer.h +++ b/include/bh/buffer.h @@ -1,6 +1,7 @@ #ifndef BH_BUFFER_H #define BH_BUFFER_H +#include "bh.h" #include "io.h" typedef struct bh_buffer_s bh_buffer_t; diff --git a/include/bh/config.in b/include/bh/config.in index 5820781..87ff147 100644 --- a/include/bh/config.in +++ b/include/bh/config.in @@ -1,10 +1,8 @@ #ifndef BH_CONFIG_H #define BH_CONFIG_H -#cmakedefine BH_USE_WINTHREAD -#cmakedefine BH_USE_PTHREAD -#cmakedefine BH_NO_WINXP #cmakedefine BH_PLATFORM_POSIX #cmakedefine BH_PLATFORM_WIN +#cmakedefine BH_PLATFORM_THREADS #endif /* BH_CONFIG_H */ diff --git a/include/bh/deflate.h b/include/bh/deflate.h index 7d9eaba..08821b0 100644 --- a/include/bh/deflate.h +++ b/include/bh/deflate.h @@ -1,5 +1,6 @@ #ifndef BH_DEFLATE_H #define BH_DEFLATE_H +#include "bh.h" #endif /* BH_DEFLATE_H */ diff --git a/include/bh/file.h b/include/bh/file.h index 3410f74..8a0d3b1 100644 --- a/include/bh/file.h +++ b/include/bh/file.h @@ -1,6 +1,7 @@ #ifndef BH_FILE_H #define BH_FILE_H +#include "bh.h" #include "io.h" typedef struct bh_file_s bh_file_t; diff --git a/include/bh/internal/bh.h b/include/bh/internal/bh.h new file mode 100644 index 0000000..5738c88 --- /dev/null +++ b/include/bh/internal/bh.h @@ -0,0 +1,7 @@ +#ifndef BH_INTERNAL_H +#define BH_INTERNAL_H + +#include <bh/bh.h> +#include <bh/internal/config.h> + +#endif /* BH_INTERNAL_H */
\ No newline at end of file diff --git a/include/bh/internal/buffer.h b/include/bh/internal/buffer.h index ab033b6..4e232d8 100644 --- a/include/bh/internal/buffer.h +++ b/include/bh/internal/buffer.h @@ -1,6 +1,7 @@ #ifndef BH_INTERNAL_BUFFER_H #define BH_INTERNAL_BUFFER_H +#include "bh.h" #include <bh/buffer.h> struct bh_buffer_s diff --git a/include/bh/internal/config.in b/include/bh/internal/config.in new file mode 100644 index 0000000..5be792c --- /dev/null +++ b/include/bh/internal/config.in @@ -0,0 +1,6 @@ +#ifndef BH_INTERNAL_CONFIG_H +#define BH_INTERNAL_CONFIG_H + +#cmakedefine BH_THREADS_WINXP + +#endif /* BH_INTERNAL_CONFIG_H */
\ No newline at end of file diff --git a/include/bh/internal/file.h b/include/bh/internal/file.h index f23cf29..1e9fed0 100644 --- a/include/bh/internal/file.h +++ b/include/bh/internal/file.h @@ -1,6 +1,7 @@ #ifndef BH_INTERNAL_FILE_H #define BH_INTERNAL_FILE_H +#include "bh.h" #include "io.h" #include <bh/file.h> diff --git a/include/bh/internal/hashmap.h b/include/bh/internal/hashmap.h index 416611d..6b59393 100644 --- a/include/bh/internal/hashmap.h +++ b/include/bh/internal/hashmap.h @@ -1,6 +1,7 @@ #ifndef BH_INTERNAL_HASHMAP_H #define BH_INTERNAL_HASHMAP_H +#include "bh.h" #include <bh/hashmap.h> typedef struct bh_hashmap_node_s diff --git a/include/bh/internal/io.h b/include/bh/internal/io.h index 988982c..d0be93b 100644 --- a/include/bh/internal/io.h +++ b/include/bh/internal/io.h @@ -1,6 +1,7 @@ #ifndef BH_INTERNAL_IO_H #define BH_INTERNAL_IO_H +#include "bh.h" #include <bh/io.h> void bh_io_init(bh_io_t *io, diff --git a/include/bh/internal/queue.h b/include/bh/internal/queue.h index fd3d8e8..04a5568 100644 --- a/include/bh/internal/queue.h +++ b/include/bh/internal/queue.h @@ -1,6 +1,7 @@ #ifndef BH_INTERNAL_QUEUE_H #define BH_INTERNAL_QUEUE_H +#include "bh.h" #include <bh/queue.h> struct bh_queue_s diff --git a/include/bh/internal/thread.h b/include/bh/internal/thread.h index 8ef9487..4f3e37e 100644 --- a/include/bh/internal/thread.h +++ b/include/bh/internal/thread.h @@ -1,6 +1,7 @@ #ifndef BH_INTERNAL_THREAD_H #define BH_INTERNAL_THREAD_H +#include "bh.h" #include <bh/thread.h> #include "queue.h" @@ -8,9 +9,9 @@ #define BH_MAX_TLS 32 -#if defined(BH_USE_PTHREAD) +#if defined(BH_PLATFORM_POSIX) && defined(BH_PLATFORM_THREADS) #include "thread_posix.h" -#elif defined(BH_USE_WINTHREAD) +#elif defined(BH_PLATFORM_WIN) && defined(BH_PLATFORM_THREADS) #include "thread_win.h" #else #include "thread_null.h" diff --git a/include/bh/thread.h b/include/bh/thread.h index 598f4f7..7cc92fb 100644 --- a/include/bh/thread.h +++ b/include/bh/thread.h @@ -14,12 +14,7 @@ typedef struct bh_task_s bh_task_t; typedef struct bh_thread_pool_s bh_thread_pool_t; typedef struct bh_spinlock_s bh_spinlock_t; -#if defined(BH_USE_PTHREAD) -bh_thread_t *bh_thread_new(bh_task_t *task); - -bh_thread_pool_t *bh_thread_pool_new(size_t size); - -#elif defined(BH_USE_WINTHREAD) +#if defined(BH_PLATFORM_WIN) && defined(BH_PLATFORM_THREADS) #include <windows.h> #include <process.h> @@ -46,6 +41,10 @@ bh_thread_pool_t *bh_thread_pool_new_base(size_t size, #define bh_thread_pool_new(size) \ bh_thread_pool_new_base((size), _beginthreadex, _endthreadex); +#elif defined(BH_PLATFORM_THREADS) +bh_thread_t *bh_thread_new(bh_task_t *task); + +bh_thread_pool_t *bh_thread_pool_new(size_t size); #endif bh_task_t *bh_task_new(void (*func)(void *), diff --git a/src/thread_win.c b/src/thread_win.c index 3b78f46..16a6d68 100644 --- a/src/thread_win.c +++ b/src/thread_win.c @@ -187,7 +187,7 @@ int bh_semaphore_try_wait(bh_semaphore_t *semaphore) return BH_OK; } -#if WINVER >= _WIN32_WINNT_VISTA +#if WINVER >= _WIN32_WINNT_VISTA && !defined(BH_THREADS_WINXP) int bh_cond_init(bh_cond_t *cond) { InitializeConditionVariable(&cond->handle); |
