Support the dynlock API

Also actually run tests after compiling them >_>
Clean up locking code a bit