From c0874b638211c5223f24aefc5cc44c2482db2f5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DELRIEU?= Date: Wed, 16 Oct 2019 12:32:34 +0200 Subject: [PATCH 1/3] mingw: allow users to override pthread lib name with PTW32_LIB_NAME --- build/Jamfile.v2 | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index 1a88d0102..50f46aefe 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -16,6 +16,8 @@ # You need to provide the include path and lib path in the variables # PTW32_INCLUDE and PTW32_LIB respectively. You can specify these # paths in site-config.jam, user-config.jam or in the environment. +# Additionally, you can provide PTW32_LIB_NAME to overwrite the name hardcoded +# by Boost.Thread. # A new feature is provided to request a specific API: # win32 and pthread. # @@ -165,12 +167,16 @@ rule win32_pthread_paths ( properties * ) local result ; local PTW32_INCLUDE ; local PTW32_LIB ; - PTW32_INCLUDE = [ modules.peek : PTW32_INCLUDE ] ; - PTW32_LIB = [ modules.peek : PTW32_LIB ] ; - PTW32_INCLUDE ?= [ modules.peek user-config : PTW32_INCLUDE ] ; - PTW32_LIB ?= [ modules.peek user-config : PTW32_LIB ] ; - PTW32_INCLUDE ?= [ modules.peek site-config : PTW32_INCLUDE ] ; - PTW32_LIB ?= [ modules.peek site-config : PTW32_LIB ] ; + local PTW32_LIB_NAME ; + PTW32_INCLUDE = [ modules.peek : PTW32_INCLUDE ] ; + PTW32_LIB = [ modules.peek : PTW32_LIB ] ; + PTW32_LIB_NAME = [ modules.peek : PTW32_LIB_NAME ] ; + PTW32_INCLUDE ?= [ modules.peek user-config : PTW32_INCLUDE ] ; + PTW32_LIB ?= [ modules.peek user-config : PTW32_LIB ] ; + PTW32_LIB_NAME ?= [ modules.peek user-config : PTW32_LIB_NAME ] ; + PTW32_INCLUDE ?= [ modules.peek site-config : PTW32_INCLUDE ] ; + PTW32_LIB ?= [ modules.peek site-config : PTW32_LIB ] ; + PTW32_LIB_NAME ?= [ modules.peek site-config : PTW32_LIB_NAME ] ; if ! ( $(PTW32_INCLUDE) && $(PTW32_LIB) ) { @@ -192,16 +198,23 @@ rule win32_pthread_paths ( properties * ) { local include_path = [ path.make $(PTW32_INCLUDE) ] ; local lib_path = [ path.make $(PTW32_LIB) ] ; - local libname = pthread ; + local libname = $(PTW32_LIB_NAME) ; if msvc in $(properties) { - libname = $(libname)VC2.lib ; + if ! $(libname) + { + libname = libpthreadVC2.lib ; + } + lib_path = [ path.glob $(lib_path) : $(libname) ] ; } if gcc in $(properties) { - libname = lib$(libname)GC2.a ; + if ! $(libname) + { + libname = libpthreadGC2.a ; + } + lib_path = [ path.glob $(lib_path) : $(libname) ] ; } - lib_path = [ path.glob $(lib_path) : $(libname) ] ; if ! $(lib_path) { if ! $(.notified) @@ -210,6 +223,7 @@ rule win32_pthread_paths ( properties * ) echo "Trying to build Boost.Thread with pthread support." ; echo "But the library" $(libname) "could not be found in path" ; echo $(PTW32_LIB) ; + echo "You can force the library name by setting PTW32_LIB_NAME " ; echo "************************************************************" ; .notified = true ; } @@ -316,4 +330,4 @@ lib boost_thread @usage-requirements ; -boost-install boost_thread ; \ No newline at end of file +boost-install boost_thread ; From e5d50b40d82ea66dc42d448fa6200a05b991a812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DELRIEU?= Date: Wed, 16 Oct 2019 12:36:55 +0200 Subject: [PATCH 2/3] mingw: use GetSystemInfo to retrieve page size --- include/boost/thread/pthread/thread_data.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/boost/thread/pthread/thread_data.hpp b/include/boost/thread/pthread/thread_data.hpp index aefbeb43c..719656b4c 100644 --- a/include/boost/thread/pthread/thread_data.hpp +++ b/include/boost/thread/pthread/thread_data.hpp @@ -32,6 +32,10 @@ # endif #endif +#ifdef __MINGW32__ +#include +#endif + #include #include @@ -52,7 +56,11 @@ namespace boost // stack void set_stack_size(std::size_t size) BOOST_NOEXCEPT { if (size==0) return; -#ifdef BOOST_THREAD_USES_GETPAGESIZE +#ifdef __MINGW32__ + SYSTEM_INFO si; + GetSystemInfo(&si); + std::size_t page_size = si.dwPageSize; +#elif defined(BOOST_THREAD_USES_GETPAGESIZE) std::size_t page_size = getpagesize(); #else std::size_t page_size = ::sysconf( _SC_PAGESIZE); From ecc80d4687b51e95d1d04f64f6f6a128f7088607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DELRIEU?= Date: Thu, 31 Oct 2019 16:12:41 +0100 Subject: [PATCH 3/3] do not use monotonic clocks with MinGW + pthreads According to MinGW pthread source code, the monotonic clocks are not supported. --- include/boost/thread/detail/config.hpp | 4 +++- include/boost/thread/detail/platform.hpp | 4 +++- include/boost/thread/pthread/thread_data.hpp | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/boost/thread/detail/config.hpp b/include/boost/thread/detail/config.hpp index faffa0778..8e89aee70 100644 --- a/include/boost/thread/detail/config.hpp +++ b/include/boost/thread/detail/config.hpp @@ -421,7 +421,9 @@ # endif #endif -#if defined(BOOST_THREAD_CHRONO_WINDOWS_API) +#if defined(BOOST_THREAD_MINGW) && defined(BOOST_THREAD_PLATFORM_PTHREAD) +// MinGW pthread does not support monotonic clocks +#elif defined(BOOST_THREAD_CHRONO_WINDOWS_API) #define BOOST_THREAD_HAS_MONO_CLOCK #define BOOST_THREAD_INTERNAL_CLOCK_IS_MONO #elif defined(BOOST_THREAD_CHRONO_MAC_API) diff --git a/include/boost/thread/detail/platform.hpp b/include/boost/thread/detail/platform.hpp index 172a601a0..1b700562a 100644 --- a/include/boost/thread/detail/platform.hpp +++ b/include/boost/thread/detail/platform.hpp @@ -17,7 +17,9 @@ #include // choose platform -#if defined(linux) || defined(__linux) || defined(__linux__) +#ifdef __MINGW32__ +#define BOOST_THREAD_MINGW +#elif defined(linux) || defined(__linux) || defined(__linux__) # define BOOST_THREAD_LINUX //# define BOOST_THREAD_WAIT_BUG boost::posix_time::microseconds(100000) #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) diff --git a/include/boost/thread/pthread/thread_data.hpp b/include/boost/thread/pthread/thread_data.hpp index 719656b4c..e07898208 100644 --- a/include/boost/thread/pthread/thread_data.hpp +++ b/include/boost/thread/pthread/thread_data.hpp @@ -32,7 +32,7 @@ # endif #endif -#ifdef __MINGW32__ +#ifdef BOOST_THREAD_MINGW #include #endif @@ -56,7 +56,7 @@ namespace boost // stack void set_stack_size(std::size_t size) BOOST_NOEXCEPT { if (size==0) return; -#ifdef __MINGW32__ +#ifdef BOOST_THREAD_MINGW SYSTEM_INFO si; GetSystemInfo(&si); std::size_t page_size = si.dwPageSize;