Redesign of database locking.

This allows to lock the database in two steps: obtaining the file lock
first and then obtaining the thread lock. Obtaining the thread lock is
now supported non-blocking from a state machine (DatabaseThreadLock).

To get access to the database one needs a BackEndAccess object
(where its operator->() gives access to the LockedBackEnd singleton).
Before there was only a blocking way to get this access.
To now get access in a blocking way, the most straightforward would be:

  DatabaseFileLock file_lock;                               // Throws if another viewer has locked the database.
  DatabaseThreadLock thread_lock(file_lock);                // Does not yet lock the mutex (doesn't block).
  ScopedBlockingBackEndAccess back_end_access(thread_lock); // Blocks until this thread could lock the mutex.
  // Use back_end_access->...

which is also exception safe.

Note that thread_lock is a state machine that can also be 'run'.
Doing so will cause it to finish once it obtained the lock on the
mutex - and the database can then be accessed through
thread_lock.back_end_access(), in the callback.