Skip to content

Fix/mingw pthread #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions build/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -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:
# <threadapi>win32 and <threadapi>pthread.
#
Expand Down Expand Up @@ -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) )
{
Expand All @@ -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 <toolset>msvc in $(properties)
{
libname = $(libname)VC2.lib ;
if ! $(libname)
{
libname = libpthreadVC2.lib ;
}
lib_path = [ path.glob $(lib_path) : $(libname) ] ;
}
if <toolset>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)
Expand All @@ -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 ;
}
Expand Down Expand Up @@ -316,4 +330,4 @@ lib boost_thread
<conditional>@usage-requirements
;

boost-install boost_thread ;
boost-install boost_thread ;
4 changes: 3 additions & 1 deletion include/boost/thread/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion include/boost/thread/detail/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#include <boost/config/requires_threads.hpp>

// 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__)
Expand Down
10 changes: 9 additions & 1 deletion include/boost/thread/pthread/thread_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
# endif
#endif

#ifdef BOOST_THREAD_MINGW
#include <sysinfoapi.h>
#endif

#include <pthread.h>
#include <unistd.h>

Expand All @@ -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 BOOST_THREAD_MINGW
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);
Expand Down