This PR handles concurrent wallet loading.
This can be tested by running in parallel the following script a couple of times:
0for i in {1..10}
1do
2 src/bitcoin-cli -regtest loadwallet foo
3 src/bitcoin-cli -regtest unloadwallet foo
4done
Eventually the error occurs:
0error code: -4
1error message:
2Wallet already being loading.
For reference, loading and already loaded wallet gives:
0error code: -4
1error message:
2Wallet file verification failed. Error loading wallet w1. Duplicate -wallet filename specified.
Fixes #19232.