There is now a
\Drupal::lock() function, which returns an instance of the locking layer.
Drupal 7 (these functions have been removed)
$lock = \Drupal::lock();
Additionally, the functionality in
_lock_id() has been moved to