Add advisory file locking.

This commit adds advisory locking via flock() to the database file. This ensures that two separate processes cannot both open the same data file which would cause corruption.

Fixes #110.