Skip to content

Commit 92e6ff0

Browse files
committed
Revert pull request lballabio#1491.
1 parent 6cf1ac8 commit 92e6ff0

13 files changed

Lines changed: 159 additions & 100 deletions

CMakeLists.txt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,15 @@ if (NOT DEFINED QL_BOOST_VERSION)
125125
endif()
126126
endif()
127127

128-
find_package(Boost ${QL_BOOST_VERSION} REQUIRED)
128+
if (NOT DEFINED QL_BOOST_COMPONENTS)
129+
set(QL_BOOST_COMPONENTS "")
130+
# Boost thread needed for sessions, singleton thread-safe init and thread-safe observer pattern
131+
if(QL_ENABLE_SESSIONS OR QL_ENABLE_SINGLETON_THREAD_SAFE_INIT OR QL_ENABLE_THREAD_SAFE_OBSERVER_PATTERN)
132+
set(QL_BOOST_COMPONENTS "${QL_BOOST_COMPONENTS};thread")
133+
endif()
134+
endif()
135+
136+
find_package(Boost ${QL_BOOST_VERSION} REQUIRED COMPONENTS ${QL_BOOST_COMPONENTS})
129137

130138
# Do not warn about Boost versions higher than 1.58.0
131139
set(Boost_NO_WARN_NEW_VERSIONS ON)
@@ -142,18 +150,22 @@ if (NOT DEFINED THREADS_PREFER_PTHREAD_FLAG)
142150
set(THREADS_PREFER_PTHREAD_FLAG ON)
143151
endif()
144152

145-
# Add Threads dependency when any of the threading features are enabled
146-
if (QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER OR QL_ENABLE_SESSIONS OR QL_ENABLE_SINGLETON_THREAD_SAFE_INIT OR QL_ENABLE_THREAD_SAFE_OBSERVER_PATTERN)
153+
set(QL_THREAD_LIBRARIES)
154+
155+
if (QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER)
147156
find_package(Threads REQUIRED)
157+
set(QL_THREAD_LIBRARIES Threads::Threads ${QL_THREAD_LIBRARIES})
148158
# Parallel test runner needs library rt on *nix for shm_open, etc.
149-
if (QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER AND UNIX AND NOT APPLE)
159+
if (UNIX AND NOT APPLE)
150160
find_library(RT_LIBRARY rt REQUIRED)
151-
set(QL_THREAD_LIBRARIES Threads::Threads ${RT_LIBRARY})
152-
else()
153-
set(QL_THREAD_LIBRARIES Threads::Threads)
161+
set(QL_THREAD_LIBRARIES ${RT_LIBRARY} ${QL_THREAD_LIBRARIES})
154162
endif()
155163
endif()
156164

165+
if (QL_ENABLE_SESSIONS OR QL_ENABLE_SINGLETON_THREAD_SAFE_INIT OR QL_ENABLE_THREAD_SAFE_OBSERVER_PATTERN)
166+
set(QL_THREAD_LIBRARIES Boost::thread ${QL_THREAD_LIBRARIES})
167+
endif()
168+
157169
# If available, use PIC for shared libs and PIE for executables
158170
if (NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
159171
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

Examples/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ else
3030
noinst_PROGRAMS = $(EXAMPLES)
3131
endif
3232

33-
LDADDS = ../ql/libQuantLib.la ${PTHREAD_LIB}
33+
LDADDS = ../ql/libQuantLib.la ${BOOST_THREAD_LIB}
3434

3535
BasketLosses_BasketLosses_SOURCES = BasketLosses/BasketLosses.cpp
3636
BasketLosses_BasketLosses_LDADD = $(LDADDS)

acinclude.m4

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -153,38 +153,63 @@ AC_DEFUN([QL_CHECK_BOOST_UNIT_TEST],
153153
fi
154154
])
155155

156-
# QL_CHECK_BOOST_SIGNALS2
156+
# QL_CHECK_BOOST_TEST_THREAD_SIGNALS2_SYSTEM
157157
# ------------------------
158-
# Check whether Boost signals2 is available
159-
AC_DEFUN([QL_CHECK_BOOST_SIGNALS2],
160-
[AC_MSG_CHECKING([whether Boost signals2 is available])
158+
# Check whether the Boost thread and system is available
159+
AC_DEFUN([QL_CHECK_BOOST_TEST_THREAD_SIGNALS2_SYSTEM],
160+
[AC_MSG_CHECKING([whether Boost thread, signals2 and system are available])
161161
AC_REQUIRE([AC_PROG_CC])
162162
ql_original_LIBS=$LIBS
163163
ql_original_CXXFLAGS=$CXXFLAGS
164-
LIBS="$ql_original_LIBS -pthread"
165-
CXXFLAGS="$ql_original_CXXFLAGS -pthread"
166-
boost_signals2_found=no
167-
AC_LINK_IFELSE([AC_LANG_SOURCE(
168-
[@%:@include <boost/signals2/signal.hpp>
169-
170-
int main() {
171-
boost::signals2::signal<void()> sig;
172-
}
173-
])],
174-
[boost_signals2_found=yes
175-
break],
176-
[])
164+
CC_BASENAME=`basename $CC`
165+
CC_VERSION=`echo "__GNUC__ __GNUC_MINOR__" | $CC -E -x c - | tail -n 1 | $SED -e "s/ //"`
166+
for suffix in "" \
167+
"-$CC_BASENAME$CC_VERSION" \
168+
"-$CC_BASENAME" \
169+
"-mt-$CC_BASENAME$CC_VERSION" \
170+
"-$CC_BASENAME$CC_VERSION-mt" \
171+
"-x$CC_BASENAME$CC_VERSION-mt" \
172+
"-mt-$CC_BASENAME" \
173+
"-$CC_BASENAME-mt" \
174+
"-mt" ; do
175+
boost_thread_lib="-lboost_thread$suffix -lboost_system$suffix"
176+
LIBS="$ql_original_LIBS $boost_thread_lib"
177+
CXXFLAGS="$ql_original_CXXFLAGS -pthread"
178+
boost_thread_found=no
179+
AC_LINK_IFELSE([AC_LANG_SOURCE(
180+
[@%:@include <boost/thread/locks.hpp>
181+
@%:@include <boost/thread/recursive_mutex.hpp>
182+
@%:@include <boost/signals2/signal.hpp>
183+
184+
#ifndef BOOST_THREAD_PLATFORM_PTHREAD
185+
#error only pthread is supported on this plattform
186+
#endif
187+
188+
int main() {
189+
boost::recursive_mutex m;
190+
boost::lock_guard<boost::recursive_mutex> lock(m);
191+
192+
boost::signals2::signal<void()> sig;
193+
194+
return 0;
195+
}
196+
])],
197+
[boost_thread_found=$boost_thread_lib
198+
break],
199+
[])
200+
done
177201
LIBS="$ql_original_LIBS"
178202
CXXFLAGS="$ql_original_CXXFLAGS"
179203
180-
if test "$boost_signals2_found" = no ; then
204+
if test "$boost_thread_found" = no ; then
181205
AC_MSG_RESULT([no])
182-
AC_SUBST([PTHREAD_LIB],[""])
183-
AC_MSG_ERROR([Boost signals2 library not found.
184-
This library is required by the thread-safe observer pattern.])
206+
AC_SUBST([BOOST_THREAD_LIB],[""])
207+
AC_MSG_ERROR([Boost thread, signals2 and system libraries not found.
208+
These libraries are required by the thread-safe observer pattern
209+
or by the parallel unit test runner.])
185210
else
186211
AC_MSG_RESULT([yes])
187-
AC_SUBST([PTHREAD_LIB],["-pthread"])
212+
AC_SUBST([BOOST_THREAD_LIB],[$boost_thread_lib])
188213
AC_SUBST([PTHREAD_CXXFLAGS],["-pthread"])
189214
AC_SUBST([CXXFLAGS],["${CXXFLAGS} -pthread"])
190215
fi

configure.ac

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ if test [ -n "$ql_boost_include_path" ] ; then
4141
AC_SUBST([BOOST_INCLUDE],["-isystem ${ql_boost_include_path}"])
4242
AC_SUBST([CPPFLAGS],["${CPPFLAGS} -isystem ${ql_boost_include_path}"])
4343
fi
44+
AC_ARG_WITH([boost-lib],
45+
AS_HELP_STRING([--with-boost-lib=LIB_PATH],
46+
[Supply the location of Boost libraries]),
47+
[ql_boost_lib_path="`cd ${withval} 2>/dev/null && pwd`"],
48+
[ql_boost_lib_path=""])
49+
if test [ -n "$ql_boost_lib_path" ] ; then
50+
AC_SUBST([BOOST_LIB],["-L${ql_boost_lib_path}"])
51+
AC_SUBST([LDFLAGS],["${LDFLAGS} -L${ql_boost_lib_path}"])
52+
fi
53+
4454

4555
# Continue setup
4656

@@ -266,9 +276,9 @@ AC_MSG_RESULT([$ql_use_safe_singleton_init])
266276

267277
if test "$ql_use_sessions" = "yes" || test "$ql_use_tsop" = "yes" || test "$ql_use_safe_singleton_init" = "yes"; then
268278
QL_CHECK_BOOST_VERSION_1_58_OR_HIGHER
269-
QL_CHECK_BOOST_SIGNALS2
279+
QL_CHECK_BOOST_TEST_THREAD_SIGNALS2_SYSTEM
270280
else
271-
AC_SUBST([PTHREAD_LIB],[""])
281+
AC_SUBST([BOOST_THREAD_LIB],[""])
272282
fi
273283

274284
AC_MSG_CHECKING([whether to enable parallel unit test runner])

ql/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,6 +2350,9 @@ target_include_directories(ql_library SYSTEM PUBLIC
23502350
${Boost_INCLUDE_DIRS}
23512351
${OpenMP_CXX_INCLUDE_DIRS})
23522352

2353+
target_link_directories(ql_library PUBLIC
2354+
${BOOST_LIBRARY_DIRS})
2355+
23532356
target_link_libraries(ql_library PUBLIC
23542357
${OpenMP_CXX_LIBRARIES})
23552358

ql/auto_link.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,15 @@
6161
# pragma message("Will (need to) link to lib file: " QL_LIB_NAME)
6262
#endif
6363

64+
/* Also, these Boost libraries might be needed */
65+
#if defined(QL_ENABLE_SESSIONS) || defined(QL_ENABLE_THREAD_SAFE_OBSERVER_PATTERN) || defined(QL_ENABLE_SINGLETON_THREAD_SAFE_INIT)
66+
# define BOOST_LIB_NAME boost_system
67+
# include <boost/config/auto_link.hpp>
68+
# undef BOOST_LIB_NAME
69+
# define BOOST_LIB_NAME boost_thread
70+
# include <boost/config/auto_link.hpp>
71+
# undef BOOST_LIB_NAME
72+
#endif
73+
74+
6475
#endif

ql/patterns/observable.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ namespace QuantLib {
9797
public:
9898
typedef boost::signals2::signal_type<
9999
void(),
100-
boost::signals2::keywords::mutex_type<std::recursive_mutex> >
100+
boost::signals2::keywords::mutex_type<boost::recursive_mutex> >
101101
::type signal_type;
102102

103103
void connect(const signal_type::slot_type& slot) {
@@ -140,7 +140,7 @@ namespace QuantLib {
140140

141141
void Observable::registerObserver(const ext::shared_ptr<Observer::Proxy>& observerProxy) {
142142
{
143-
std::lock_guard<std::recursive_mutex> lock(mutex_);
143+
boost::lock_guard<boost::recursive_mutex> lock(mutex_);
144144
observers_.insert(observerProxy);
145145
}
146146

@@ -155,12 +155,12 @@ namespace QuantLib {
155155
void Observable::unregisterObserver(const ext::shared_ptr<Observer::Proxy>& observerProxy,
156156
bool disconnect) {
157157
{
158-
std::lock_guard<std::recursive_mutex> lock(mutex_);
158+
boost::lock_guard<boost::recursive_mutex> lock(mutex_);
159159
observers_.erase(observerProxy);
160160
}
161161

162162
if (settings_.updatesDeferred()) {
163-
std::lock_guard<std::mutex> sLock(settings_.mutex_);
163+
boost::lock_guard<boost::mutex> sLock(settings_.mutex_);
164164
if (settings_.updatesDeferred()) {
165165
settings_.unregisterDeferredObserver(observerProxy);
166166
}
@@ -176,12 +176,12 @@ namespace QuantLib {
176176
return (*sig_)();
177177
}
178178

179-
std::lock_guard<std::mutex> sLock(settings_.mutex_);
179+
boost::lock_guard<boost::mutex> sLock(settings_.mutex_);
180180
if (settings_.updatesEnabled()) {
181181
return (*sig_)();
182182
}
183183
else if (settings_.updatesDeferred()) {
184-
std::lock_guard<std::recursive_mutex> lock(mutex_);
184+
boost::lock_guard<boost::recursive_mutex> lock(mutex_);
185185
// if updates are only deferred, flag this for later notification
186186
// these are held centrally by the settings singleton
187187
settings_.registerDeferredObservers(observers_);

0 commit comments

Comments
 (0)