assorted minor misc cleanup, thread/mutex related

This lays groundwork for later work on multi-threaded sql backend.