Support the dynlock API

Also actually run tests after compiling them >_>
Clean up locking code a bit
Merge branch 'master' into andrew-fork