Add internal configuration file, add missing includes, rename some options

This commit is contained in:
2024-06-12 12:09:59 +03:00
parent 5762484550
commit bfa33b3778
15 changed files with 47 additions and 17 deletions

View File

@@ -10,6 +10,9 @@ include(CheckIPOSupported)
include(CheckIncludeFile) include(CheckIncludeFile)
include(CheckSymbolExists) include(CheckSymbolExists)
# Project settings
option(BH_PLATFORM_THREADS "Enable multithreading support" TRUE)
# Check for IPO/LTO # Check for IPO/LTO
check_ipo_supported(RESULT supported) check_ipo_supported(RESULT supported)
@@ -55,6 +58,7 @@ set(BH_INCLUDE_DIRS
if(WIN32) if(WIN32)
message(STATUS "Platform - Win32") message(STATUS "Platform - Win32")
set(BH_PLATFORM_WIN TRUE) set(BH_PLATFORM_WIN TRUE)
option(BH_THREADS_WINXP "Enable threading support for Windows XP" FALSE)
# Add platform dependent files # Add platform dependent files
list(APPEND BH_SOURCE list(APPEND BH_SOURCE
@@ -62,8 +66,11 @@ if(WIN32)
) )
# Check multithreading support # Check multithreading support
check_symbol_exists(_beginthread process.h BH_USE_WINTHREAD) if(BH_PLATFORM_THREADS)
if(BH_USE_WINTHREAD) check_symbol_exists(_beginthread process.h BH_PLATFORM_THREADS)
endif()
if(BH_PLATFORM_THREADS)
message(STATUS "Multithreading enabled") message(STATUS "Multithreading enabled")
list(APPEND BH_SOURCE list(APPEND BH_SOURCE
src/thread_win.c src/thread_win.c
@@ -75,7 +82,7 @@ if(WIN32)
) )
endif() endif()
if(BH_NO_WINXP) if(NOT BH_THREADS_WINXP)
add_definitions(-D_WIN32_WINNT=_WIN32_WINNT_VISTA -DWINVER=_WIN32_WINNT_VISTA) add_definitions(-D_WIN32_WINNT=_WIN32_WINNT_VISTA -DWINVER=_WIN32_WINNT_VISTA)
endif() endif()
elseif(UNIX) elseif(UNIX)
@@ -88,8 +95,11 @@ elseif(UNIX)
) )
# Check multithreading support # Check multithreading support
check_include_file(pthread.h BH_USE_PTHREAD) if(BH_PLATFORM_THREADS)
if(BH_USE_PTHREAD) check_include_file(pthread.h BH_PLATFORM_THREADS)
endif()
if(BH_PLATFORM_THREADS)
message(STATUS "Multithreading enabled") message(STATUS "Multithreading enabled")
list(APPEND BH_SOURCE list(APPEND BH_SOURCE
src/thread_posix.c src/thread_posix.c
@@ -111,6 +121,7 @@ endif()
# Configure library # Configure library
configure_file(include/bh/config.in include/bh/config.h) configure_file(include/bh/config.in include/bh/config.h)
configure_file(include/bh/internal/config.in include/bh/internal/config.h)
# Library # Library
add_library(bhlib STATIC ${BH_SOURCE} ${BH_HEADER}) add_library(bhlib STATIC ${BH_SOURCE} ${BH_HEADER})

View File

@@ -1,6 +1,7 @@
#ifndef BH_BUFFER_H #ifndef BH_BUFFER_H
#define BH_BUFFER_H #define BH_BUFFER_H
#include "bh.h"
#include "io.h" #include "io.h"
typedef struct bh_buffer_s bh_buffer_t; typedef struct bh_buffer_s bh_buffer_t;

View File

@@ -1,10 +1,8 @@
#ifndef BH_CONFIG_H #ifndef BH_CONFIG_H
#define 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_POSIX
#cmakedefine BH_PLATFORM_WIN #cmakedefine BH_PLATFORM_WIN
#cmakedefine BH_PLATFORM_THREADS
#endif /* BH_CONFIG_H */ #endif /* BH_CONFIG_H */

View File

@@ -1,5 +1,6 @@
#ifndef BH_DEFLATE_H #ifndef BH_DEFLATE_H
#define BH_DEFLATE_H #define BH_DEFLATE_H
#include "bh.h"
#endif /* BH_DEFLATE_H */ #endif /* BH_DEFLATE_H */

View File

@@ -1,6 +1,7 @@
#ifndef BH_FILE_H #ifndef BH_FILE_H
#define BH_FILE_H #define BH_FILE_H
#include "bh.h"
#include "io.h" #include "io.h"
typedef struct bh_file_s bh_file_t; typedef struct bh_file_s bh_file_t;

7
include/bh/internal/bh.h Normal file
View File

@@ -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 */

View File

@@ -1,6 +1,7 @@
#ifndef BH_INTERNAL_BUFFER_H #ifndef BH_INTERNAL_BUFFER_H
#define BH_INTERNAL_BUFFER_H #define BH_INTERNAL_BUFFER_H
#include "bh.h"
#include <bh/buffer.h> #include <bh/buffer.h>
struct bh_buffer_s struct bh_buffer_s

View File

@@ -0,0 +1,6 @@
#ifndef BH_INTERNAL_CONFIG_H
#define BH_INTERNAL_CONFIG_H
#cmakedefine BH_THREADS_WINXP
#endif /* BH_INTERNAL_CONFIG_H */

View File

@@ -1,6 +1,7 @@
#ifndef BH_INTERNAL_FILE_H #ifndef BH_INTERNAL_FILE_H
#define BH_INTERNAL_FILE_H #define BH_INTERNAL_FILE_H
#include "bh.h"
#include "io.h" #include "io.h"
#include <bh/file.h> #include <bh/file.h>

View File

@@ -1,6 +1,7 @@
#ifndef BH_INTERNAL_HASHMAP_H #ifndef BH_INTERNAL_HASHMAP_H
#define BH_INTERNAL_HASHMAP_H #define BH_INTERNAL_HASHMAP_H
#include "bh.h"
#include <bh/hashmap.h> #include <bh/hashmap.h>
typedef struct bh_hashmap_node_s typedef struct bh_hashmap_node_s

View File

@@ -1,6 +1,7 @@
#ifndef BH_INTERNAL_IO_H #ifndef BH_INTERNAL_IO_H
#define BH_INTERNAL_IO_H #define BH_INTERNAL_IO_H
#include "bh.h"
#include <bh/io.h> #include <bh/io.h>
void bh_io_init(bh_io_t *io, void bh_io_init(bh_io_t *io,

View File

@@ -1,6 +1,7 @@
#ifndef BH_INTERNAL_QUEUE_H #ifndef BH_INTERNAL_QUEUE_H
#define BH_INTERNAL_QUEUE_H #define BH_INTERNAL_QUEUE_H
#include "bh.h"
#include <bh/queue.h> #include <bh/queue.h>
struct bh_queue_s struct bh_queue_s

View File

@@ -1,6 +1,7 @@
#ifndef BH_INTERNAL_THREAD_H #ifndef BH_INTERNAL_THREAD_H
#define BH_INTERNAL_THREAD_H #define BH_INTERNAL_THREAD_H
#include "bh.h"
#include <bh/thread.h> #include <bh/thread.h>
#include "queue.h" #include "queue.h"
@@ -8,9 +9,9 @@
#define BH_MAX_TLS 32 #define BH_MAX_TLS 32
#if defined(BH_USE_PTHREAD) #if defined(BH_PLATFORM_POSIX) && defined(BH_PLATFORM_THREADS)
#include "thread_posix.h" #include "thread_posix.h"
#elif defined(BH_USE_WINTHREAD) #elif defined(BH_PLATFORM_WIN) && defined(BH_PLATFORM_THREADS)
#include "thread_win.h" #include "thread_win.h"
#else #else
#include "thread_null.h" #include "thread_null.h"

View File

@@ -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_thread_pool_s bh_thread_pool_t;
typedef struct bh_spinlock_s bh_spinlock_t; typedef struct bh_spinlock_s bh_spinlock_t;
#if defined(BH_USE_PTHREAD) #if defined(BH_PLATFORM_WIN) && 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);
#elif defined(BH_USE_WINTHREAD)
#include <windows.h> #include <windows.h>
#include <process.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) \ #define bh_thread_pool_new(size) \
bh_thread_pool_new_base((size), _beginthreadex, _endthreadex); 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 #endif
bh_task_t *bh_task_new(void (*func)(void *), bh_task_t *bh_task_new(void (*func)(void *),

View File

@@ -187,7 +187,7 @@ int bh_semaphore_try_wait(bh_semaphore_t *semaphore)
return BH_OK; 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) int bh_cond_init(bh_cond_t *cond)
{ {
InitializeConditionVariable(&cond->handle); InitializeConditionVariable(&cond->handle);