Redesign of database locking.

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

The get access to the database one needs a BackEndAccess object
(where it's operator->() gives access to the LockedBackEnd singleton).
Before there was only a blocking way to get this access. To 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 (don't block).
  ScopedBlockingBackEndAccess back_end_access(thread_lock); // Blocks until this thread could obtain 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.