Compile with DEBUG_LOCKORDER to detect inconsistent lock orderings that can cause deadlocks

Backported from bitcoin commit 865ed8a1e5c587468a40756d46bcbc1c5a12bb06
Fix to remain compatible with DEBUG_LOCKORDER
Fix rpc-hanging deadlocks

Collapsed multiple wallet mutexes to a single cs_wallet, to avoid deadlocks with wallet methods that acquired locks in different order.
Also change master RPC call handler to acquire cs_main and cs_wallet locks before executing RPC calls; requiring each RPC call to acquire the right set of locks in the right order was too error-prone.

Backported from bitcoin commit 6cc4a62c0e696dcb9d90ba0504f688e4f644a10f
Reduce debug message for async RPC call threads when no threads
Changed semantics of CWalletTx::GetTxTime(); now always returns the time the transaction was received by this node, not the average block time.
Fix AddAddress cs_mapaddresses/db transaction deadlock

Backported from bitcoin commit 940669657837e4a247a4d0746c12f52e8662f325
Fix compilation for qt
temp
Highlight mis-matching locks
If compiled -DDEBUG_LOCKORDER and run with -debug, print out every mutex lock/unlock (helpful for debugging something-is-holding-a-mutex-too-long problems)
Single DB transaction for addresses from DNS seeds
Backported from bitcoin commit d655a26c9dd157a9e4bf08bff14bfaa69791287a
Fix some address-handling deadlocks

Made three critical blocks for cs_mapAddresses smaller, and moved
writing to the database out of them. This should also improve the
concurrency of the code.

Backported partialy from bitcoin commit a75d7066b824eb1e70fb5b0e0e7c3c122e00c4b6
Fix crashes when a wallet is locked and GetReservedKey() is called
Add DEBUG_LOCKCONTENTION, to warn each time a thread waits to lock.

If compiled with -DDEBUG_LOCKCONTENTION, Bitcoin will print to
debug.log each time a thread has to wait for a lock to continue.
Revert "Fix crashes when a wallet is locked and GetReservedKey() is called"

This reverts commit f01a0c956d11e40fe3492313e786d11520d4c092.
Macros for manual critical sections
Fix wallet locking locking

Backported from bitcoin commit b0529ffd951fdaa7ecc823381a6a7b0c88b5b2b0
Locking system overhaul, add condition variables

This commit simplifies the locking system: CCriticalSection becomes a
simple typedef for boost::interprocess::interprocess_recursive_mutex,
and CCriticalBlock and CTryCriticalBlock are replaced by a templated
CMutexLock, which wraps boost::interprocess::scoped_lock.

By making the lock type a template parameter, some critical sections
can now be changed to non-recursive locks, which support waiting via
condition variables. These are implemented in CWaitableCriticalSection
and WAITABLE_CRITICAL_BLOCK.

CWaitableCriticalSection is a wrapper for a different Boost mutex,
which supports waiting/notification via condition variables. This
should enable us to remove much of the used polling code. Important
is that this mutex is not recursive, so functions that perform the
locking must not call eachother.

Because boost::interprocess::scoped_lock does not support assigning
and copying, I had to revert to the older CRITICAL_BLOCK macros that
use a nested for loop instead of a simple if.

Backported from bitcoin commit 712fd182b72b0f5a1bcf843f171c29ec0a49b50f