Vasil Dimov
4df6567e4c
sync: make EnterCritical() & push_lock() type safe
...
The functions `EnterCritical()` and `push_lock()` take a pointer to a
mutex, but that pointer used to be of type `void*` because we use a few
different types for mutexes. This `void*` argument was not type safe
because somebody could have send a pointer to anything that is not a
mutex. Furthermore it wouldn't allow to check whether the passed mutex
is recursive or not.
Thus, change the functions to templated ones so that we can implement
stricter checks for non-recursive mutexes. This also simplifies the
callers of `EnterCritical()`.
2020-08-05 09:42:42 +02:00
Hennadii Stepanov
63e9e40b73
test: Add LockStackEmpty()
2020-08-02 16:42:39 +03:00
Hennadii Stepanov
1f96be25b0
Preserve initial state if push_lock() throws exception
2020-08-02 16:42:33 +03:00
Hennadii Stepanov
0ecff9dd34
Improve "detected inconsistent lock order" error message
2020-06-25 21:27:34 +03:00
Hennadii Stepanov
bbe9cf4fe4
test: Improve "potential deadlock detected" exception message
2020-06-22 18:24:29 +03:00
Hennadii Stepanov
35599344c8
Fix mistakenly swapped "previous" and "current" lock orders
2020-06-22 18:12:26 +03:00
Hennadii Stepanov
971a468ccf
Use template function instead of void* parameter
...
This change gets rid of -Wthread-safety-attributes warning spam.
2020-05-28 09:55:04 +03:00
Hennadii Stepanov
90eb027204
doc: Add and fix comments about never destroyed objects
2020-05-22 15:45:21 +03:00
Hennadii Stepanov
26c093a995
Replace thread_local g_lockstack with a mutex-protected map
...
This change prevents UB in case of early g_lockstack destroying.
Co-authored-by: Wladimir J. van der Laan <laanwj@protonmail.com>
2020-05-19 01:14:08 +03:00
Hennadii Stepanov
58e6881bc5
refactor: Refactor duplicated code into LockHeld()
2020-05-19 01:14:07 +03:00
Hennadii Stepanov
f511f61dda
refactor: Add LockPair type alias
2020-05-19 01:14:07 +03:00
Hennadii Stepanov
8d8921abd3
refactor: Add LockStackItem type alias
2020-05-19 01:14:07 +03:00
Hennadii Stepanov
458992b06d
Prevent UB in DeleteLock() function
2020-05-19 01:13:49 +03:00
MarcoFalke
fac96fff62
util: Remove unused itostr
2020-03-27 08:59:06 -04:00
Anthony Towns
b9c4260127
sync.h: add REVERSE_LOCK
2020-03-06 23:13:31 +10:00
MarcoFalke
e09c701e01
scripted-diff: Bump copyright of files changed in 2020
...
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-
2020-01-15 02:18:00 +07:00
MarcoFalke
6cbe620964
scripted-diff: Replace CCriticalSection with RecursiveMutex
...
-BEGIN VERIFY SCRIPT-
# Delete outdated alias for RecursiveMutex
sed -i -e '/CCriticalSection/d' ./src/sync.h
# Replace use of outdated alias with RecursiveMutex
sed -i -e 's/CCriticalSection/RecursiveMutex/g' $(git grep -l CCriticalSection)
-END VERIFY SCRIPT-
2020-01-15 01:43:46 +07:00
MarcoFalke
aaaaad6ac9
scripted-diff: Bump copyright of files changed in 2019
...
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-
2019-12-30 10:42:20 +13:00
Wladimir J. van der Laan
c72906dcc1
refactor: Remove redundant c_str() calls in formatting
...
Our formatter, tinyformat, *never* needs `c_str()` for strings.
Remove redundant `c_str()` calls for:
- `strprintf`
- `LogPrintf`
- `tfm::format`
2019-10-28 13:31:33 +01:00
practicalswift
084e17cebd
Remove unused includes
2019-10-15 22:56:43 +00:00
MarcoFalke
fa8f195195
Replace remaining fprintf with tfm::format manually
2019-06-13 11:46:38 -04:00
MarcoFalke
fac03ec43a
scripted-diff: Replace fprintf with tfm::format
...
-BEGIN VERIFY SCRIPT-
sed -i --regexp-extended -e 's/fprintf\(std(err|out), /tfm::format(std::c\1, /g' $(git grep -l 'fprintf(' -- ':(exclude)src/crypto' ':(exclude)src/leveldb' ':(exclude)src/univalue' ':(exclude)src/secp256k1')
-END VERIFY SCRIPT-
fixup! scripted-diff: Replace fprintf with tfm::format
2019-06-13 10:32:52 -04:00
orient
41ab2a8924
fix static_assert for macro HAVE_THREAD_LOCAL
...
fix static_assert for macro HAVE_THREAD_LOCAL while define DEBUG_LOCKCONTENTION
2019-05-07 14:11:35 +08:00
James O'Beirne
8722e54e56
threads: add thread names to deadlock debugging message
...
Also refactor CLockLocation to use an initialization list.
2019-04-29 13:51:59 -04:00
Akio Nakamura
b09dab0f2d
Prevent mutex lock fail even if --enable-debug
...
This PR intends to resolve #15227 .
"configure --debug-enabled" enables "#ifdef DEBUG_LOCKORDER".
Then "lockdata" (in sync.cpp) will be initialized same as other
static objects.
But unfortunately, lockdata.push_lock() was called before its
initialization (via initializing signatureCache which is declared
in script/sigcache.cpp) on macOS.
This PR apply the "Construct On First Use Idiom" to "lockdata"
to prevent it.
2019-01-25 13:21:59 +09:00
Jim Posen
2068f089c8
scripted-diff: Move util files to separate directory.
...
-BEGIN VERIFY SCRIPT-
mkdir -p src/util
git mv src/util.h src/util/system.h
git mv src/util.cpp src/util/system.cpp
git mv src/utilmemory.h src/util/memory.h
git mv src/utilmoneystr.h src/util/moneystr.h
git mv src/utilmoneystr.cpp src/util/moneystr.cpp
git mv src/utilstrencodings.h src/util/strencodings.h
git mv src/utilstrencodings.cpp src/util/strencodings.cpp
git mv src/utiltime.h src/util/time.h
git mv src/utiltime.cpp src/util/time.cpp
sed -i 's/<util\.h>/<util\/system\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp')
sed -i 's/<utilmemory\.h>/<util\/memory\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp')
sed -i 's/<utilmoneystr\.h>/<util\/moneystr\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp')
sed -i 's/<utilstrencodings\.h>/<util\/strencodings\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp')
sed -i 's/<utiltime\.h>/<util\/time\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp')
sed -i 's/BITCOIN_UTIL_H/BITCOIN_UTIL_SYSTEM_H/g' src/util/system.h
sed -i 's/BITCOIN_UTILMEMORY_H/BITCOIN_UTIL_MEMORY_H/g' src/util/memory.h
sed -i 's/BITCOIN_UTILMONEYSTR_H/BITCOIN_UTIL_MONEYSTR_H/g' src/util/moneystr.h
sed -i 's/BITCOIN_UTILSTRENCODINGS_H/BITCOIN_UTIL_STRENCODINGS_H/g' src/util/strencodings.h
sed -i 's/BITCOIN_UTILTIME_H/BITCOIN_UTIL_TIME_H/g' src/util/time.h
sed -i 's/ util\.\(h\|cpp\)/ util\/system\.\1/g' src/Makefile.am
sed -i 's/utilmemory\.\(h\|cpp\)/util\/memory\.\1/g' src/Makefile.am
sed -i 's/utilmoneystr\.\(h\|cpp\)/util\/moneystr\.\1/g' src/Makefile.am
sed -i 's/utilstrencodings\.\(h\|cpp\)/util\/strencodings\.\1/g' src/Makefile.am
sed -i 's/utiltime\.\(h\|cpp\)/util\/time\.\1/g' src/Makefile.am
sed -i 's/-> util ->/-> util\/system ->/' test/lint/lint-circular-dependencies.sh
sed -i 's/src\/util\.cpp/src\/util\/system\.cpp/g' test/lint/lint-format-strings.py test/lint/lint-locale-dependence.sh
sed -i 's/src\/utilmoneystr\.cpp/src\/util\/moneystr\.cpp/g' test/lint/lint-locale-dependence.sh
sed -i 's/src\/utilstrencodings\.\(h\|cpp\)/src\/util\/strencodings\.\1/g' test/lint/lint-locale-dependence.sh
sed -i 's/src\\utilstrencodings\.cpp/src\\util\\strencodings\.cpp/' build_msvc/libbitcoinconsensus/libbitcoinconsensus.vcxproj
-END VERIFY SCRIPT-
2018-11-04 22:46:07 -08:00
Wladimir J. van der Laan
385ad11040
Merge #11640 : Make LOCK, LOCK2, TRY_LOCK work with CWaitableCriticalSection
...
9c4dc597dd
Use LOCK macros for non-recursive locks (Russell Yanofsky)
1382913e61
Make LOCK, LOCK2, TRY_LOCK work with CWaitableCriticalSection (Russell Yanofsky)
ba1f095aad
MOVEONLY Move AnnotatedMixin declaration (Russell Yanofsky)
41b88e9337
Add unit test for DEBUG_LOCKORDER code (Russell Yanofsky)
Pull request description:
Make LOCK macros work with non-recursive mutexes, and use wherever possible for better deadlock detection.
Also add unit test for DEBUG_LOCKORDER code.
Tree-SHA512: 64ef209307f28ecd0813a283f15c6406138c6ffe7f6cbbd084161044db60e2c099a7d0d2edcd1c5e7770a115e9b931b486e86c9a777bdc96d2e8a9f4dc192942
2018-08-31 16:00:38 +02:00
Russell Yanofsky
41b88e9337
Add unit test for DEBUG_LOCKORDER code
2018-08-03 07:11:37 -05:00
DrahtBot
eb7daf4d60
Update copyright headers to 2018
2018-07-27 07:15:02 -04:00
MarcoFalke
fa9da85b7c
qa: Initialize lockstack to prevent null pointer deref
2018-05-22 06:31:26 -04:00
Chun Kuan Lee
84f41946b9
break circular dependency: random/sync -> util -> random/sync
2018-05-17 08:13:54 +00:00
John Newbery
5c21e6c6d3
[logging] Comment all continuing logs.
...
Most logs should terminated with a '\n'. Some logs
are built up over multiple calls to logPrintf(), so
do not need a newline terminater. Comment all of
these 'continued' logs as a linter hing.
2018-04-07 12:29:48 -04:00
Wladimir J. van der Laan
bd59c4395c
Merge #12859 : Bugfix: Include <memory> for std::unique_ptr
...
a5bca13
Bugfix: Include <memory> for std::unique_ptr (Luke Dashjr)
Pull request description:
Not sure why all these includes were missing, but it's breaking builds for some users:
https://bugs.gentoo.org/show_bug.cgi?id=652142
(Added to all files with a reference to `std::unique_ptr`)
Tree-SHA512: 8a2c67513ca07b9bb52c34e8a20b15e56f8af2530310d9ee9b0a69694dd05e02e7a3683f14101a2685d457672b56addec591a0bb83900a0eb8e2a43d43200509
2018-04-05 09:31:53 +02:00
Luke Dashjr
a5bca13095
Bugfix: Include <memory> for std::unique_ptr
2018-04-02 18:31:52 +00:00
practicalswift
1340eda3b7
Fix typos
2018-01-28 13:21:25 +01:00
Akira Takizawa
595a7bab23
Increment MIT Licence copyright header year on files modified in 2017
2018-01-03 02:26:56 +09:00
Cory Fields
f7f7e2cd34
threads: add a thread_local autoconf check
2017-11-27 15:01:47 -08:00
Thomas Snider
bba9bd0d9d
Switched sync.{cpp,h} to std threading primitives.
2017-11-18 11:35:14 -08:00
MeshCollider
1a445343f6
scripted-diff: Replace #include "" with #include <> (ryanofsky)
...
-BEGIN VERIFY SCRIPT-
for f in \
src/*.cpp \
src/*.h \
src/bench/*.cpp \
src/bench/*.h \
src/compat/*.cpp \
src/compat/*.h \
src/consensus/*.cpp \
src/consensus/*.h \
src/crypto/*.cpp \
src/crypto/*.h \
src/crypto/ctaes/*.h \
src/policy/*.cpp \
src/policy/*.h \
src/primitives/*.cpp \
src/primitives/*.h \
src/qt/*.cpp \
src/qt/*.h \
src/qt/test/*.cpp \
src/qt/test/*.h \
src/rpc/*.cpp \
src/rpc/*.h \
src/script/*.cpp \
src/script/*.h \
src/support/*.cpp \
src/support/*.h \
src/support/allocators/*.h \
src/test/*.cpp \
src/test/*.h \
src/wallet/*.cpp \
src/wallet/*.h \
src/wallet/test/*.cpp \
src/wallet/test/*.h \
src/zmq/*.cpp \
src/zmq/*.h
do
base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f
done
-END VERIFY SCRIPT-
2017-11-16 08:23:01 +13:00
Matt Corallo
2b4b34503f
Add ability to assert a lock is not held in DEBUG_LOCKORDER
2017-10-13 19:29:54 -04:00
João Barbosa
92848e5058
Remove unused fTry from push_lock
2017-09-30 22:43:55 +01:00
practicalswift
36d326e8b0
Use nullptr instead of zero (0) as the null pointer constant
2017-08-16 10:24:18 +02:00
practicalswift
90d4d89230
scripted-diff: Use the C++11 keyword nullptr to denote the pointer literal instead of the macro NULL
...
-BEGIN VERIFY SCRIPT-
sed -i 's/\<NULL\>/nullptr/g' src/*.cpp src/*.h src/*/*.cpp src/*/*.h src/qt/*/*.cpp src/qt/*/*.h src/wallet/*/*.cpp src/wallet/*/*.h src/support/allocators/*.h
sed -i 's/Prefer nullptr, otherwise SAFECOOKIE./Prefer NULL, otherwise SAFECOOKIE./g' src/torcontrol.cpp
sed -i 's/tor: Using nullptr authentication/tor: Using NULL authentication/g' src/torcontrol.cpp
sed -i 's/METHODS=nullptr/METHODS=NULL/g' src/test/torcontrol_tests.cpp src/torcontrol.cpp
sed -i 's/nullptr certificates/NULL certificates/g' src/qt/paymentserver.cpp
sed -i 's/"nullptr"/"NULL"/g' src/torcontrol.cpp src/test/torcontrol_tests.cpp
-END VERIFY SCRIPT-
2017-08-07 07:36:37 +02:00
Jorge Timón
5995735c5b
scripted-diff: Remove #include <boost/foreach.hpp>
...
-BEGIN VERIFY SCRIPT-
sed -i ':a;N;$!ba;s/#include <boost\/foreach.hpp>\n//' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ./src/*/*/*.h ./src/*/*/*.cpp
-END VERIFY SCRIPT-
2017-06-22 03:48:52 +02:00
Jorge Timón
1238f13cf6
scripted-diff: Remove PAIRTYPE
...
-BEGIN VERIFY SCRIPT-
sed -i 's/PAIRTYPE(\([^,]*\), \([^\)]*\))/std::pair<\1, \2>/' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ./src/*/*/*.h ./src/*/*/*.cpp ;
sed -i ':a;N;$!ba;s/#define std::pair<t1, t2> std::pair<t1, t2>\n//' ./src/utilstrencodings.h ;
-END VERIFY SCRIPT-
2017-06-05 20:14:53 +02:00
Jorge Timón
7c00c26726
scripted-diff: Fully remove BOOST_FOREACH
...
-BEGIN VERIFY SCRIPT-
sed -i 's/BOOST_FOREACH *(\(.*\),/for (\1 :/' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ./src/*/*/*.h ./src/*/*/*.cpp ;
-END VERIFY SCRIPT-
2017-06-05 20:10:50 +02:00
practicalswift
8dc957ae06
Remove unused code
2017-03-17 04:37:43 +01:00
Matt Corallo
618ee9249b
Further-enforce lockordering by enforcing directly after TRY_LOCKs
2017-02-07 14:15:28 -05:00
Matt Corallo
8465631845
Always enforce lock strict lock ordering (try or not)
2017-02-02 22:31:27 -05:00
isle2983
27765b6403
Increment MIT Licence copyright header year on files modified in 2016
...
Edited via:
$ contrib/devtools/copyright_header.py update .
2016-12-31 11:01:21 -07:00