Added optional PostgreSQL compilation.
Added log-specific lock.
Switched to CRITICAL_SECTION from MUTEX in Windows (vastly better performance for uncontested locks).
Small cleanups.
Removed a load of mutexes (but haven't tested yet).