Skip to content

Commit 618ad71

Browse files
committed
Build libumf_pool_scalable on Windows
Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 1682326 commit 618ad71

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/pool/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,18 @@ if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
5353
endif()
5454

5555
# libumf_pool_scalable
56+
if(LINUX)
57+
set(LIBS_POOL_SCALABLE dl umf_utils)
58+
elseif(WINDOWS)
59+
set(LIBS_POOL_SCALABLE umf_utils)
60+
endif()
61+
5662
if(UMF_BUILD_LIBUMF_POOL_SCALABLE)
57-
if(LINUX)
63+
if(LINUX OR WINDOWS)
5864
add_umf_library(NAME scalable_pool
5965
TYPE STATIC
6066
SRCS pool_scalable.c ${POOL_EXTRA_SRCS}
61-
LIBS dl umf_utils)
67+
LIBS ${LIBS_POOL_SCALABLE})
6268
target_compile_definitions(scalable_pool PUBLIC ${POOL_COMPILE_DEFINITIONS})
6369
add_library(${PROJECT_NAME}::scalable_pool ALIAS scalable_pool)
6470
install(TARGETS scalable_pool

src/pool/pool_scalable.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
*
88
*/
99

10-
#include <assert.h>
10+
#ifndef _WIN32
1111
#include <dlfcn.h>
1212
#include <pthread.h>
13+
#endif
14+
15+
#include <assert.h>
1316
#include <stdbool.h>
1417
#include <stdint.h>
1518
#include <stdio.h>
@@ -62,11 +65,20 @@ static struct tbb_callbacks g_tbb_ops;
6265
static UTIL_ONCE_FLAG tbb_is_initialized = UTIL_ONCE_FLAG_INIT;
6366
static bool Init_tbb_global_state_failed;
6467

68+
#ifdef _WIN32
69+
#define dlsym(handle, symbol) GetProcAddress(handle, symbol)
70+
#define dlclose(handle) (void)(handle)
71+
#endif
72+
6573
static void init_tbb_global_state(void) {
66-
const char so_name[] = "libtbbmalloc.so.2";
67-
void *tbb_handle = dlopen(so_name, RTLD_LAZY);
74+
const char lib_name[] = "libtbbmalloc.so.2";
75+
#ifdef _WIN32
76+
HMODULE tbb_handle = LoadLibrary(TEXT(lib_name));
77+
#else
78+
void *tbb_handle = dlopen(lib_name, RTLD_LAZY);
79+
#endif
6880
if (!tbb_handle) {
69-
fprintf(stderr, "%s not found.\n", so_name);
81+
fprintf(stderr, "%s not found.\n", lib_name);
7082
Init_tbb_global_state_failed = true;
7183
return;
7284
}
@@ -95,7 +107,7 @@ static void init_tbb_global_state(void) {
95107
!tbb_ops.pool_aligned_malloc || !tbb_ops.pool_free ||
96108
!tbb_ops.pool_create_v1 || !tbb_ops.pool_destroy ||
97109
!tbb_ops.pool_identify) {
98-
fprintf(stderr, "Could not find symbols in %s.\n", so_name);
110+
fprintf(stderr, "Could not find symbols in %s.\n", lib_name);
99111
dlclose(tbb_handle);
100112
Init_tbb_global_state_failed = true;
101113
return;

0 commit comments

Comments
 (0)