Initial changes to make lock.c self-init

TODO:

 - do the same for dynlocks
 - consider rw locks instead of mutexes
 - add an extra macro guard around all of this?