MDL-25500 locking: Refactor locking

This refactor allows different instances of lock_factories to be used
by different systems in Moodle.
They are all configured separately in the config.php file.