Prevent UB in DeleteLock() function
Summary:
- refactor: Add LockStackItem type alias
- refactor: Add LockPair type alias
- refactor: Refactor duplicated code into LockHeld()
- 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>
- doc: Add and fix comments about never destroyed objects
This is a backport of Core PR18881
Test Plan:
ninja all check-all
Also in debug mode.
Reviewers: #bitcoin_abc, majcosta
Reviewed By: #bitcoin_abc, majcosta
Subscribers: majcosta
Differential Revision: https://reviews.bitcoinabc.org/D7525