diff --git a/configure.ac b/configure.ac index 139166b6d149060dbb09e7ceb6b1639c27d5cf4c..b02143b4be07931abb31a5f438036e722b62e979 100644 --- a/configure.ac +++ b/configure.ac @@ -66,6 +66,11 @@ if test $enable_shared = no; then AC_MSG_ERROR([BIND 10 requires shared libraries to be built]) fi +AC_ARG_ENABLE(boost-threads, +AC_HELP_STRING([--enable-boost-threads], + [use boost threads. Currently this only means using its locks instead of dummy locks, in the cache and NSAS]), + use_boost_threads=$enableval, use_boost_threads=no) + # allow configuring without setproctitle. AC_ARG_ENABLE(setproctitle-check, AC_HELP_STRING([--disable-setproctitle-check], @@ -443,62 +448,69 @@ AC_CHECK_HEADERS([boost/shared_ptr.hpp boost/foreach.hpp boost/interprocess/sync CPPFLAGS="$CPPFLAGS_SAVES" AC_SUBST(BOOST_INCLUDES) -# Using boost::mutex can result in requiring libboost_thread with older -# versions of Boost. We'd like to avoid relying on a compiled Boost library -# whenever possible, so we need to check for it step by step. -# -# NOTE: another fix of this problem is to simply require newer versions of -# boost. If we choose that solution we should simplify the following tricky -# checks accordingly and all Makefile.am's that refer to NEED_LIBBOOST_THREAD. -AC_MSG_CHECKING(for boost::mutex) -CPPFLAGS_SAVES="$CPPFLAGS" -LIBS_SAVES="$LIBS" -CPPFLAGS="$BOOST_INCLUDES $CPPFLAGS $MULTITHREADING_FLAG" -need_libboost_thread=0 -need_sunpro_workaround=0 -AC_TRY_LINK([ -#include -],[ -boost::mutex m; -], - [ AC_MSG_RESULT(yes (without libboost_thread)) ], - - # there is one specific problem with SunStudio 5.10 - # where including boost/thread causes a compilation failure - # There is a workaround in boost but it checks the version not being 5.10 - # This will probably be fixed in the future, in which case this - # is only a temporary workaround - [ AC_TRY_LINK([ -#if defined(__SUNPRO_CC) && __SUNPRO_CC == 0x5100 -#undef __SUNPRO_CC -#define __SUNPRO_CC 0x5090 -#endif -#include -],[ -boost::mutex m; -], - [ AC_MSG_RESULT(yes (with SUNOS workaround)) - need_sunpro_workaround=1 ], - [ LIBS=" $LIBS -lboost_thread" - AC_TRY_LINK([ -#include -],[ -boost::mutex m; -], - [ AC_MSG_RESULT(yes (with libboost_thread)) - need_libboost_thread=1 ], - [ AC_MSG_RESULT(no) - AC_MSG_ERROR([boost::mutex cannot be linked in this build environment. -Perhaps you are using an older version of Boost that requires libboost_thread for the mutex support, which does not appear to be available. -You may want to check the availability of the library or to upgrade Boost.]) - ])])]) -CPPFLAGS="$CPPFLAGS_SAVES" -LIBS="$LIBS_SAVES" -AM_CONDITIONAL(NEED_LIBBOOST_THREAD, test $need_libboost_thread = 1) -if test $need_sunpro_workaround = 1; then - AC_DEFINE([NEED_SUNPRO_WORKAROUND], [], [Need boost sunstudio workaround]) + +if test "${use_boost_threads}" = "yes" ; then + AC_DEFINE([USE_BOOST_THREADS], [], [Use boost threads]) + + # Using boost::mutex can result in requiring libboost_thread with older + # versions of Boost. We'd like to avoid relying on a compiled Boost library + # whenever possible, so we need to check for it step by step. + # + # NOTE: another fix of this problem is to simply require newer versions of + # boost. If we choose that solution we should simplify the following tricky + # checks accordingly and all Makefile.am's that refer to NEED_LIBBOOST_THREAD. + AC_MSG_CHECKING(for boost::mutex) + CPPFLAGS_SAVES="$CPPFLAGS" + LIBS_SAVES="$LIBS" + CPPFLAGS="$BOOST_INCLUDES $CPPFLAGS $MULTITHREADING_FLAG" + need_libboost_thread=0 + need_sunpro_workaround=0 + AC_TRY_LINK([ + #include + ],[ + boost::mutex m; + ], + [ AC_MSG_RESULT(yes (without libboost_thread)) ], + # there is one specific problem with SunStudio 5.10 + # where including boost/thread causes a compilation failure + # There is a workaround in boost but it checks the version not being 5.10 + # This will probably be fixed in the future, in which case this + # is only a temporary workaround + [ AC_TRY_LINK([ + #if defined(__SUNPRO_CC) && __SUNPRO_CC == 0x5100 + #undef __SUNPRO_CC + #define __SUNPRO_CC 0x5090 + #endif + #include + ],[ + boost::mutex m; + ], + [ AC_MSG_RESULT(yes (with SUNOS workaround)) + need_sunpro_workaround=1 ], + [ LIBS=" $LIBS -lboost_thread" + AC_TRY_LINK([ + #include + ],[ + boost::mutex m; + ], + [ AC_MSG_RESULT(yes (with libboost_thread)) + need_libboost_thread=1 ], + [ AC_MSG_RESULT(no) + AC_MSG_ERROR([boost::mutex cannot be linked in this build environment. + Perhaps you are using an older version of Boost that requires libboost_thread for the mutex support, which does not appear to be available. + You may want to check the availability of the library or to upgrade Boost.]) + ])])]) + CPPFLAGS="$CPPFLAGS_SAVES" + LIBS="$LIBS_SAVES" + AM_CONDITIONAL(NEED_LIBBOOST_THREAD, test $need_libboost_thread = 1) + if test $need_sunpro_workaround = 1; then + AC_DEFINE([NEED_SUNPRO_WORKAROUND], [], [Need boost sunstudio workaround]) + fi +else + AM_CONDITIONAL(NEED_LIBBOOST_THREAD, test "${use_boost_threads}" = "yes") fi + # # Check availability of gtest, which will be used for unit tests. # diff --git a/src/bin/auth/tests/query_unittest.cc b/src/bin/auth/tests/query_unittest.cc index 2d3cf03a621ea6d00a3f453d9898b802ef2ba66a..05dd748da988850dde718586ab83f13ce4be968b 100644 --- a/src/bin/auth/tests/query_unittest.cc +++ b/src/bin/auth/tests/query_unittest.cc @@ -201,7 +201,7 @@ MockZone::find(const Name& name, const RRType& type, // If not found but we have a target, fill it with all RRsets here if (!found_domain->second.empty() && target != NULL) { for (found_rrset = found_domain->second.begin(); - found_rrset != found_domain->second.end(); found_rrset++) { + found_rrset != found_domain->second.end(); ++found_rrset) { // Insert RRs under the domain name into target target->addRRset( boost::const_pointer_cast(found_rrset->second)); diff --git a/src/lib/datasrc/data_source.cc b/src/lib/datasrc/data_source.cc index 8b2b47e3a49180b71cc550cf8ce30b45c5d31315..829d1fcf7735392e86c2ae8d80b20847457778fc 100644 --- a/src/lib/datasrc/data_source.cc +++ b/src/lib/datasrc/data_source.cc @@ -1157,7 +1157,7 @@ MetaDataSrc::addDataSrc(ConstDataSrcPtr data_src) { void MetaDataSrc::removeDataSrc(ConstDataSrcPtr data_src) { std::vector::iterator it, itr; - for (it = data_sources.begin(); it != data_sources.end(); it++) { + for (it = data_sources.begin(); it != data_sources.end(); ++it) { if (*it == data_src) { itr = it; } diff --git a/src/lib/datasrc/memory_datasrc.cc b/src/lib/datasrc/memory_datasrc.cc index bbc5166fb31e64ee6f38dc670342e36f385d1f0a..bf3c8ca7db649808720ae571210023ade40eb62e 100644 --- a/src/lib/datasrc/memory_datasrc.cc +++ b/src/lib/datasrc/memory_datasrc.cc @@ -515,7 +515,7 @@ struct MemoryZone::MemoryZoneImpl { if (target != NULL && !node->getData()->empty()) { // Empty domain will be handled as NXRRSET by normal processing for (found = node->getData()->begin(); - found != node->getData()->end(); found++) + found != node->getData()->end(); ++found) { target->addRRset( boost::const_pointer_cast(prepareRRset(name, diff --git a/src/lib/nsas/Makefile.am b/src/lib/nsas/Makefile.am index a88bd22dc3e3e8c0ea120deac97e6969a65767e7..04a765b86c7a43a5d25f7a04b70fc58aec7880d1 100644 --- a/src/lib/nsas/Makefile.am +++ b/src/lib/nsas/Makefile.am @@ -25,6 +25,7 @@ libnsas_la_SOURCES += asiolink.h libnsas_la_SOURCES += hash.cc hash.h libnsas_la_SOURCES += hash_deleter.h libnsas_la_SOURCES += hash_key.cc hash_key.h +libnsas_la_SOURCES += locks.h libnsas_la_SOURCES += hash_table.h libnsas_la_SOURCES += lru_list.h libnsas_la_SOURCES += nameserver_address_store.cc nameserver_address_store.h diff --git a/src/lib/nsas/hash_table.h b/src/lib/nsas/hash_table.h index 3c34ee9a110eb0fa2d74de44a3e4e7a177168741..e46d687b0f6171f24700b653f01d29813e650d21 100644 --- a/src/lib/nsas/hash_table.h +++ b/src/lib/nsas/hash_table.h @@ -15,25 +15,11 @@ #ifndef __HASH_TABLE_H #define __HASH_TABLE_H -// Workaround for a problem with boost and sunstudio 5.10 -// There is a version check in there that appears wrong, -// which makes including boost/thread.hpp fail -// This will probably be fixed in a future version of boost, -// in which case this part can be removed then -#ifdef NEED_SUNPRO_WORKAROUND -#if defined(__SUNPRO_CC) && __SUNPRO_CC == 0x5100 -#undef __SUNPRO_CC -#define __SUNPRO_CC 0x5090 -#endif -#endif // NEED_SUNPRO_WORKAROUND +#include #include -#include -#include -#include -#include -#include +#include "locks.h" #include "hash.h" #include "hash_key.h" @@ -61,7 +47,7 @@ struct HashTableSlot { typedef typename std::list >::iterator iterator; ///< Iterator over elements with same hash - typedef boost::interprocess::interprocess_upgradable_mutex mutex_type; + typedef isc::locks::upgradable_mutex mutex_type; ///< Mutex protecting this slot //@} @@ -128,11 +114,11 @@ public: /// //@{ typedef typename - boost::interprocess::sharable_lock::mutex_type> + isc::locks::sharable_lock::mutex_type> sharable_lock; ///< Type for a scope-limited read-lock typedef typename - boost::interprocess::scoped_lock::mutex_type> + isc::locks::scoped_lock::mutex_type> scoped_lock; ///< Type for a scope-limited write-lock //@} diff --git a/src/lib/nsas/locks.h b/src/lib/nsas/locks.h new file mode 100644 index 0000000000000000000000000000000000000000..98197c3eb0ac73a0923af8053cf435a1c0142fca --- /dev/null +++ b/src/lib/nsas/locks.h @@ -0,0 +1,116 @@ +// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +/// This file (right now) provides dummy locks +/// It also contains code to use boost/threads locks: +/// +/// if USE_BOOST_THREADS is defined, we typedef the relevant classes +/// and derive from the relevant templates so our dummy locks are +/// replaced by the boost locks (--enable-boost-threads) +/// +/// If USE_BOOST_THREADS is NOT defined, all locks are dummy classes +/// that don't actually do anything. At this moment, only the very +/// minimal set of methods that we actually use is defined. +/// +/// Note that we need to include in our .cc files for that +/// to be set. we might want to enfore this at compile time with a check +/// (TODO) +/// Note that this also contains a workaround for Sunstudio; which +/// probably won't completely work right now (that is, if the TODO +/// above is completed), since that would also require some changes +/// in most (at first glance unrelated) Makefiles +/// (TODO2) + +#ifndef __LOCKS_ +#define __LOCKS_ + +#ifndef USE_BOOST_THREADS + +namespace isc { +namespace locks { + +class mutex { +}; + +class recursive_mutex { +}; + +class upgradable_mutex { +}; + +template +class sharable_lock { +public: + sharable_lock(T) { } +}; + +template +class scoped_lock { +public: + scoped_lock(T) { } + + void lock() {} + void unlock() {} +}; + +} +} + +#else // USE_BOOST_THREADS + +// Workaround for a problem with boost and sunstudio 5.10 +// There is a version check in there that appears wrong, +// which makes including boost/thread.hpp fail +// This will probably be fixed in a future version of boost, +// in which case this part can be removed then +#ifdef NEED_SUNPRO_WORKAROUND +#if defined(__SUNPRO_CC) && __SUNPRO_CC == 0x5100 +#undef __SUNPRO_CC +#define __SUNPRO_CC 0x5090 +#endif +#endif // NEED_SUNPRO_WORKAROUND + +#include +#include +#include +#include +#include + +namespace isc { +namespace locks { + +typedef boost::mutex mutex; +typedef boost::interprocess::interprocess_upgradable_mutex upgradable_mutex; +typedef boost::interprocess::interprocess_recursive_mutex recursive_mutex; + +template +struct sharable_lock : public boost::interprocess::sharable_lock { +public: + sharable_lock(T& mtype) : boost::interprocess::sharable_lock(mtype) {} +}; + + +template +struct scoped_lock : public boost::interprocess::scoped_lock { +public: + scoped_lock(T& mtype) : boost::interprocess::scoped_lock(mtype) { } +}; + +} +} + + +#endif // USE_BOOST_THREADS + +#endif // __LOCKS_ diff --git a/src/lib/nsas/lru_list.h b/src/lib/nsas/lru_list.h index a3e0974440d743981bdbac9c37720103d5e42572..993eb89cc1ea2e1c7a5041cf028b464c6f2fe822 100644 --- a/src/lib/nsas/lru_list.h +++ b/src/lib/nsas/lru_list.h @@ -18,22 +18,10 @@ #include #include -// Workaround for a problem with boost and sunstudio 5.10 -// There is a version check in there that appears wrong, -// which makes including boost/thread.hpp fail -// This will probably be fixed in a future version of boost, -// in which case this part can be removed then -#ifdef NEED_SUNPRO_WORKAROUND -#if defined(__SUNPRO_CC) && __SUNPRO_CC == 0x5100 -#undef __SUNPRO_CC -#define __SUNPRO_CC 0x5090 -#endif -#endif // NEED_SUNPRO_WORKAROUND - #include #include -#include -#include + +#include "locks.h" namespace isc { namespace nsas { @@ -151,7 +139,7 @@ public: } private: - boost::mutex mutex_; ///< List protection + isc::locks::mutex mutex_; ///< List protection std::list > lru_; ///< The LRU list itself uint32_t max_size_; ///< Max size of the list uint32_t count_; ///< Count of elements @@ -163,7 +151,7 @@ template void LruList::add(boost::shared_ptr& element) { // Protect list against concurrent access - boost::interprocess::scoped_lock lock(mutex_); + isc::locks::scoped_lock lock(mutex_); // Add the entry and set its pointer field to point into the list. // insert() is used to get the pointer. @@ -212,7 +200,7 @@ void LruList::remove(boost::shared_ptr& element) { if (element->iteratorValid()) { // Is valid, so protect list against concurrent access - boost::interprocess::scoped_lock lock(mutex_); + isc::locks::scoped_lock lock(mutex_); lru_.erase(element->getLruIterator()); // Remove element from list element->invalidateIterator(); // Invalidate pointer @@ -228,7 +216,7 @@ void LruList::touch(boost::shared_ptr& element) { if (element->iteratorValid()) { // Protect list against concurrent access - boost::interprocess::scoped_lock lock(mutex_); + isc::locks::scoped_lock lock(mutex_); // Move the element to the end of the list. lru_.splice(lru_.end(), lru_, element->getLruIterator()); diff --git a/src/lib/nsas/nameserver_address_store.cc b/src/lib/nsas/nameserver_address_store.cc index 0ba9c8ebda26d201ae9187fe3ba5ee65aa98f5fb..7bb0eee553f040ee6e555bc41f40494dcabfd5e7 100644 --- a/src/lib/nsas/nameserver_address_store.cc +++ b/src/lib/nsas/nameserver_address_store.cc @@ -14,20 +14,6 @@ #include -// Workaround for a problem with boost and sunstudio 5.10 -// There is a version check in there that appears wrong, -// which makes including boost/thread.hpp fail -// This will probably be fixed in a future version of boost, -// in which case this part can be removed then -#ifdef NEED_SUNPRO_WORKAROUND -#if defined(__SUNPRO_CC) && __SUNPRO_CC == 0x5100 -#undef __SUNPRO_CC -#define __SUNPRO_CC 0x5090 -#endif -#endif // NEED_SUNPRO_WORKAROUND - - -#include #include #include #include @@ -35,6 +21,7 @@ #include #include +#include "locks.h" #include "hash_table.h" #include "lru_list.h" #include "hash_deleter.h" diff --git a/src/lib/nsas/nameserver_entry.cc b/src/lib/nsas/nameserver_entry.cc index 53f423363a78d66072ad3c2baf49ea529cd8d46e..9522e81ff9653217c8c8d93d120f55491c301808 100644 --- a/src/lib/nsas/nameserver_entry.cc +++ b/src/lib/nsas/nameserver_entry.cc @@ -50,7 +50,7 @@ namespace nsas { namespace { // Just shorter type alias -typedef boost::recursive_mutex::scoped_lock Lock; +typedef isc::locks::scoped_lock Lock; } diff --git a/src/lib/nsas/nameserver_entry.h b/src/lib/nsas/nameserver_entry.h index 9a8e542a7e1993f29562f6bdbc4e876e1b72685e..c3ddcd488a33dfbef59a7837a54f43c915c9d8e0 100644 --- a/src/lib/nsas/nameserver_entry.h +++ b/src/lib/nsas/nameserver_entry.h @@ -15,21 +15,8 @@ #ifndef __NAMESERVER_ENTRY_H #define __NAMESERVER_ENTRY_H -// Workaround for a problem with boost and sunstudio 5.10 -// There is a version check in there that appears wrong, -// which makes including boost/thread.hpp fail -// This will probably be fixed in a future version of boost, -// in which case this part can be removed then -#ifdef NEED_SUNPRO_WORKAROUND -#if defined(__SUNPRO_CC) && __SUNPRO_CC == 0x5100 -#undef __SUNPRO_CC -#define __SUNPRO_CC 0x5090 -#endif -#endif // NEED_SUNPRO_WORKAROUND - #include #include -#include #include #include @@ -252,7 +239,7 @@ public: //@} private: - mutable boost::recursive_mutex mutex_; ///< Mutex protecting this object + mutable isc::locks::recursive_mutex mutex_;///< Mutex protecting this object std::string name_; ///< Canonical name of the nameserver isc::dns::RRClass classCode_; ///< Class of the nameserver /** diff --git a/src/lib/nsas/tests/nsas_test.h b/src/lib/nsas/tests/nsas_test.h index b4446a46a9c91eba7242a7a72d198b53cd5d1f53..926e85916cd952e02e17db38ad29f0bd95fa7878 100644 --- a/src/lib/nsas/tests/nsas_test.h +++ b/src/lib/nsas/tests/nsas_test.h @@ -22,6 +22,7 @@ #include #include +#include #include diff --git a/src/lib/nsas/zone_entry.cc b/src/lib/nsas/zone_entry.cc index 395b06c462405979d59583e07a3f926b035154d3..77f3dad950ad628261a80396d5eb8ff5e6192afd 100644 --- a/src/lib/nsas/zone_entry.cc +++ b/src/lib/nsas/zone_entry.cc @@ -12,6 +12,8 @@ // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. +#include + #include #include "zone_entry.h" @@ -49,7 +51,7 @@ ZoneEntry::ZoneEntry( namespace { // Shorter aliases for frequently used types -typedef boost::recursive_mutex::scoped_lock Lock; // Local lock, nameservers not locked +typedef isc::locks::scoped_lock Lock; // Local lock, nameservers not locked typedef boost::shared_ptr CallbackPtr; /* diff --git a/src/lib/nsas/zone_entry.h b/src/lib/nsas/zone_entry.h index c8196925d615ba1aa0e7b75c12b6f1bc3b46983c..28a42ead976c1e985973839f570c1ea957f7f2c7 100644 --- a/src/lib/nsas/zone_entry.h +++ b/src/lib/nsas/zone_entry.h @@ -15,22 +15,9 @@ #ifndef __ZONE_ENTRY_H #define __ZONE_ENTRY_H -// Workaround for a problem with boost and sunstudio 5.10 -// There is a version check in there that appears wrong, -// which makes including boost/thread.hpp fail -// This will probably be fixed in a future version of boost, -// in which case this part can be removed then -#ifdef NEED_SUNPRO_WORKAROUND -#if defined(__SUNPRO_CC) && __SUNPRO_CC == 0x5100 -#undef __SUNPRO_CC -#define __SUNPRO_CC 0x5090 -#endif -#endif // NEED_SUNPRO_WORKAROUND - #include #include #include -#include #include #include @@ -38,6 +25,7 @@ #include +#include "locks.h" #include "hash_key.h" #include "nsas_entry.h" #include "asiolink.h" @@ -131,7 +119,7 @@ protected: time_t expiry_; ///< Expiry time of this entry, 0 means not set //}@ private: - mutable boost::recursive_mutex mutex_; ///< Mutex protecting this zone entry + mutable isc::locks::recursive_mutex mutex_;///< Mutex protecting this zone entry std::string name_; ///< Canonical zone name isc::dns::RRClass class_code_; ///< Class code /**