mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
9996b1806a
060a2a64d4
ci: remove boost thread installation (fanquake)06e1d7d81d
build: don't build or use Boost Thread (fanquake)7097add83c
refactor: replace Boost shared_mutex with std shared_mutex in sigcache (fanquake)8e55981ef8
refactor: replace Boost shared_mutex with std shared_mutex in cuckoocache tests (fanquake) Pull request description: This replaces `boost::shared_mutex` and `boost::unique_lock` with [`std::shared_mutex`](https://en.cppreference.com/w/cpp/thread/shared_mutex) & [`std::unique_lock`](https://en.cppreference.com/w/cpp/thread/unique_lock). Even though [some concerns were raised](https://github.com/bitcoin/bitcoin/issues/16684#issuecomment-726214696) in #16684 with regard to `std::shared_mutex` being unsafe to use across some glibc versions, I still think this change is an improvement. As I mentioned in #21022, I also think trying to restrict standard library feature usage based on bugs in glibc is not only hard to do, but it's not currently clear exactly how we do that in practice (does it also extend to patching out use in our dependencies, should we be implementing more runtime checks for features we are using, when do we consider an affected glibc "old enough" not to worry about? etc). If you take a look through the [glibc bug tracker](https://sourceware.org/bugzilla/describecomponents.cgi?product=glibc) you'll no doubt find plenty of (active) bug reports for standard library code we already using. Obviously not to say we shouldn't try and avoid buggy code where possible. Two other points: [Cory mentioned in #21022](https://github.com/bitcoin/bitcoin/pull/21022#issuecomment-769274179): > It also seems reasonable to me to worry that boost hits the same underlying glibc bug, and we've just not happened to trigger the right conditions yet. Moving away from Boost to the standard library also removes the potential for differences related to Boosts configuration. Boost has multiple versions of `shared_mutex`, and what you end up using, and what it's backed by depends on: * The version of Boost. * The platform you're building for. * Which version of `BOOST_THREAD_VERSION` is defined: (2,3,4 or 5) default=2. (see [here](https://www.boost.org/doc/libs/1_70_0/doc/html/thread/build.html#thread.build.configuration) for some of the differences). * Is `BOOST_THREAD_V2_SHARED_MUTEX` defined? (not by default). If so, you might get the ["less performant, but more robust"](https://github.com/boostorg/thread/issues/230#issuecomment-475937761) version of `shared_mutex`. A lot of these factors are eliminated by our use of depends, but users will have varying configurations. It's also not inconceivable to think that a distro, or some package manager might start defining something like `BOOST_THREAD_VERSION=3`. Boost tried to change the default from 2 to 3 at one point. With this change, we no longer use Boost Thread, so this PR also removes it from depends, the build system, CI etc. Previous similar PRs were #19183 & #20922. The authors are included in the commits here. Also related to #21022 - pthread sanity checking. ACKs for top commit: laanwj: Code review ACK060a2a64d4
vasild: ACK060a2a64d4
Tree-SHA512: 572d14d8c9de20bc434511f20d3f431836393ff915b2fe9de5a47a02dca76805ad5c3fc4cceecb4cd43f3ba939a0508178c4e60e62abdbaaa6b3e8db20b75b03
105 lines
3.5 KiB
Bash
Executable File
105 lines
3.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Copyright (c) 2018-2020 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
#
|
|
# Check for duplicate includes.
|
|
# Guard against accidental introduction of new Boost dependencies.
|
|
# Check includes: Check for duplicate includes. Enforce bracket syntax includes.
|
|
|
|
export LC_ALL=C
|
|
IGNORE_REGEXP="/(leveldb|secp256k1|univalue|crc32c)/"
|
|
|
|
# cd to root folder of git repo for git ls-files to work properly
|
|
cd "$(dirname $0)/../.." || exit 1
|
|
|
|
filter_suffix() {
|
|
git ls-files | grep -E "^src/.*\.${1}"'$' | grep -Ev "${IGNORE_REGEXP}"
|
|
}
|
|
|
|
EXIT_CODE=0
|
|
|
|
for HEADER_FILE in $(filter_suffix h); do
|
|
DUPLICATE_INCLUDES_IN_HEADER_FILE=$(grep -E "^#include " < "${HEADER_FILE}" | sort | uniq -d)
|
|
if [[ ${DUPLICATE_INCLUDES_IN_HEADER_FILE} != "" ]]; then
|
|
echo "Duplicate include(s) in ${HEADER_FILE}:"
|
|
echo "${DUPLICATE_INCLUDES_IN_HEADER_FILE}"
|
|
echo
|
|
EXIT_CODE=1
|
|
fi
|
|
done
|
|
|
|
for CPP_FILE in $(filter_suffix cpp); do
|
|
DUPLICATE_INCLUDES_IN_CPP_FILE=$(grep -E "^#include " < "${CPP_FILE}" | sort | uniq -d)
|
|
if [[ ${DUPLICATE_INCLUDES_IN_CPP_FILE} != "" ]]; then
|
|
echo "Duplicate include(s) in ${CPP_FILE}:"
|
|
echo "${DUPLICATE_INCLUDES_IN_CPP_FILE}"
|
|
echo
|
|
EXIT_CODE=1
|
|
fi
|
|
done
|
|
|
|
INCLUDED_CPP_FILES=$(git grep -E "^#include [<\"][^>\"]+\.cpp[>\"]" -- "*.cpp" "*.h")
|
|
if [[ ${INCLUDED_CPP_FILES} != "" ]]; then
|
|
echo "The following files #include .cpp files:"
|
|
echo "${INCLUDED_CPP_FILES}"
|
|
echo
|
|
EXIT_CODE=1
|
|
fi
|
|
|
|
EXPECTED_BOOST_INCLUDES=(
|
|
boost/algorithm/string.hpp
|
|
boost/algorithm/string/classification.hpp
|
|
boost/algorithm/string/replace.hpp
|
|
boost/algorithm/string/split.hpp
|
|
boost/date_time/posix_time/posix_time.hpp
|
|
boost/filesystem.hpp
|
|
boost/filesystem/fstream.hpp
|
|
boost/multi_index/hashed_index.hpp
|
|
boost/multi_index/ordered_index.hpp
|
|
boost/multi_index/sequenced_index.hpp
|
|
boost/multi_index_container.hpp
|
|
boost/process.hpp
|
|
boost/signals2/connection.hpp
|
|
boost/signals2/optional_last_value.hpp
|
|
boost/signals2/signal.hpp
|
|
boost/test/unit_test.hpp
|
|
)
|
|
|
|
for BOOST_INCLUDE in $(git grep '^#include <boost/' -- "*.cpp" "*.h" | cut -f2 -d: | cut -f2 -d'<' | cut -f1 -d'>' | sort -u); do
|
|
IS_EXPECTED_INCLUDE=0
|
|
for EXPECTED_BOOST_INCLUDE in "${EXPECTED_BOOST_INCLUDES[@]}"; do
|
|
if [[ "${BOOST_INCLUDE}" == "${EXPECTED_BOOST_INCLUDE}" ]]; then
|
|
IS_EXPECTED_INCLUDE=1
|
|
break
|
|
fi
|
|
done
|
|
if [[ ${IS_EXPECTED_INCLUDE} == 0 ]]; then
|
|
EXIT_CODE=1
|
|
echo "A new Boost dependency in the form of \"${BOOST_INCLUDE}\" appears to have been introduced:"
|
|
git grep "${BOOST_INCLUDE}" -- "*.cpp" "*.h"
|
|
echo
|
|
fi
|
|
done
|
|
|
|
for EXPECTED_BOOST_INCLUDE in "${EXPECTED_BOOST_INCLUDES[@]}"; do
|
|
if ! git grep -q "^#include <${EXPECTED_BOOST_INCLUDE}>" -- "*.cpp" "*.h"; then
|
|
echo "Good job! The Boost dependency \"${EXPECTED_BOOST_INCLUDE}\" is no longer used."
|
|
echo "Please remove it from EXPECTED_BOOST_INCLUDES in $0"
|
|
echo "to make sure this dependency is not accidentally reintroduced."
|
|
echo
|
|
EXIT_CODE=1
|
|
fi
|
|
done
|
|
|
|
QUOTE_SYNTAX_INCLUDES=$(git grep '^#include "' -- "*.cpp" "*.h" | grep -Ev "${IGNORE_REGEXP}")
|
|
if [[ ${QUOTE_SYNTAX_INCLUDES} != "" ]]; then
|
|
echo "Please use bracket syntax includes (\"#include <foo.h>\") instead of quote syntax includes:"
|
|
echo "${QUOTE_SYNTAX_INCLUDES}"
|
|
echo
|
|
EXIT_CODE=1
|
|
fi
|
|
|
|
exit ${EXIT_CODE}
|