aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormattn <mattn.jp@gmail.com>2020-03-02 15:21:58 +0900
committerGitHub <noreply@github.com>2020-03-01 22:21:58 -0800
commitebd50d0cfa3664d454ffdf246fcd228c3b370a11 (patch)
tree7c8ebcd23e4fef2b38c01432eb91e9f10b69bcf9 /src
parentd465747660ecf9ebbaddf8c3db37e4a13d0c9103 (diff)
downloadpthreadpool-ebd50d0cfa3664d454ffdf246fcd228c3b370a11.tar.gz
Build on Windows/mingw64 (#6)
Support Windows/mingw64 build
Diffstat (limited to 'src')
-rw-r--r--src/threadpool-pthreads.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/threadpool-pthreads.c b/src/threadpool-pthreads.c
index 6c6a6d4..2cb834d 100644
--- a/src/threadpool-pthreads.c
+++ b/src/threadpool-pthreads.c
@@ -31,6 +31,12 @@
#endif
#endif
+#ifdef _WIN32
+# define NOMINMAX
+# include <sysinfoapi.h>
+# include <malloc.h>
+#endif
+
/* Dependencies */
#include <fxdiv.h>
@@ -424,6 +430,11 @@ static struct pthreadpool* pthreadpool_allocate(size_t threads_count) {
if (threadpool == NULL) {
return NULL;
}
+ #elif defined(_WIN32)
+ threadpool = _aligned_malloc(threadpool_size, PTHREADPOOL_CACHELINE_SIZE);
+ if (threadpool == NULL) {
+ return NULL;
+ }
#else
if (posix_memalign((void**) &threadpool, PTHREADPOOL_CACHELINE_SIZE, threadpool_size) != 0) {
return NULL;
@@ -439,8 +450,18 @@ struct pthreadpool* pthreadpool_create(size_t threads_count) {
#endif
if (threads_count == 0) {
- threads_count = (size_t) sysconf(_SC_NPROCESSORS_ONLN);
+ #if defined(_SC_NPROCESSORS_ONLN)
+ threads_count = (size_t) sysconf(_SC_NPROCESSORS_ONLN);
+ #elif defined(_WIN32)
+ SYSTEM_INFO system_info;
+ ZeroMemory(&system_info, sizeof(system_info));
+ GetSystemInfo(&system_info);
+ threads_count = (size_t) system_info.dwNumberOfProcessors;
+ #else
+ #error "Unsupported platform"
+ #endif
}
+
struct pthreadpool* threadpool = pthreadpool_allocate(threads_count);
if (threadpool == NULL) {
return NULL;
@@ -1204,6 +1225,10 @@ void pthreadpool_destroy(struct pthreadpool* threadpool) {
pthread_cond_destroy(&threadpool->command_condvar);
#endif
}
- free(threadpool);
+ #ifdef _WIN32
+ _aligned_free(threadpool);
+ #else
+ free(threadpool);
+ #endif
}
}