Ensure single-threaded db access

SQLite doesn't really like concurrent access so mediate it with
a lock.

Change-Id: Ibb7aed2a5f028a2a01b61b37fa24f634e4898fbe