Improve locking mechanism in QlApplication::lock()