diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index cb38421..36b56b8 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -221,53 +221,9 @@ public static function keyValueExpirable($collection) { /** * Returns the locking layer instance. * - * Method to coordinate long-running operations across requests. - * - * In most environments, multiple Drupal page requests (a.k.a. threads or - * processes) will execute in parallel. This leads to potential conflicts or - * race conditions when two requests execute the same code at the same time. A - * common example of this is a rebuild like menu_router_rebuild() where we - * invoke many hook implementations to get and process data from all active - * modules, and then delete the current data in the database to insert the new - * afterwards. - * - * This is a cooperative, advisory lock system. Any long-running operation - * that could potentially be attempted in parallel by multiple requests should - * try to acquire a lock before proceeding. By obtaining a lock, one request - * notifies any other requests that a specific operation is in progress which - * must not be executed in parallel. - * - * To use this API, pick a unique name for the lock. A sensible choice is the - * name of the function performing the operation. A very simple example use of - * this API: - * @code - * function mymodule_long_operation() { - * if (\Drupal::lock()->acquire('mymodule_long_operation')) { - * // Do the long operation here. - * // ... - * \Drupal::lock()->release('mymodule_long_operation'); - * } - * } - * @endcode - * - * If a function acquires a lock it should always release it when the operation - * is complete by calling \Drupal::lock()->release(), as in the example. - * - * A function that has acquired a lock may attempt to renew a lock (extend the - * duration of the lock) by calling \Drupal::lock()->acquire() again during the - * operation. Failure to renew a lock is indicative that another request has - * acquired the lock, and that the current operation may need to be aborted. - * - * If a function fails to acquire a lock it may either immediately return, or it may - * call \Drupal::lock()->wait() if the rest of the current page request requires that - * the operation in question be complete. After \Drupal::lock()->wait() returns, the - * function may again attempt to acquire the lock, or may simply allow the page - * request to proceed on the assumption that a parallel request completed the operation. - * - * \Drupal::lock()->acquire() and \Drupal::lock()->wait() will automatically break (delete) - * a lock whose duration has exceeded the timeout specified when it was acquired. - * * @return \Drupal\Core\Lock\LockBackendInterface + * + * @ingroup lock */ public static function lock() { return static::$container->get('lock'); diff --git a/core/lib/Drupal/Core/Lock/DatabaseLockBackend.php b/core/lib/Drupal/Core/Lock/DatabaseLockBackend.php index f3cd803..2024272 100644 --- a/core/lib/Drupal/Core/Lock/DatabaseLockBackend.php +++ b/core/lib/Drupal/Core/Lock/DatabaseLockBackend.php @@ -12,6 +12,8 @@ /** * Defines the database lock backend. This is the default backend in Drupal. + * + * @ingroup lock */ class DatabaseLockBackend extends LockBackendAbstract { diff --git a/core/lib/Drupal/Core/Lock/LockBackendAbstract.php b/core/lib/Drupal/Core/Lock/LockBackendAbstract.php index f6ca89c..1b9e194 100644 --- a/core/lib/Drupal/Core/Lock/LockBackendAbstract.php +++ b/core/lib/Drupal/Core/Lock/LockBackendAbstract.php @@ -9,6 +9,8 @@ /** * Non backend related common methods implementation for lock backends. + * + * @ingroup lock */ abstract class LockBackendAbstract implements LockBackendInterface { diff --git a/core/lib/Drupal/Core/Lock/LockBackendInterface.php b/core/lib/Drupal/Core/Lock/LockBackendInterface.php index 438f89c..97e255d 100644 --- a/core/lib/Drupal/Core/Lock/LockBackendInterface.php +++ b/core/lib/Drupal/Core/Lock/LockBackendInterface.php @@ -8,7 +8,63 @@ namespace Drupal\Core\Lock; /** + * @defgroup lock Locking mechanisms + * @{ + * Functions to coordinate long-running operations across requests. + * + * In most environments, multiple Drupal page requests (a.k.a. threads or + * processes) will execute in parallel. This leads to potential conflicts or + * race conditions when two requests execute the same code at the same time. A + * common example of this is a rebuild like menu_router_rebuild() where we + * invoke many hook implementations to get and process data from all active + * modules, and then delete the current data in the database to insert the new + * afterwards. + * + * This is a cooperative, advisory lock system. Any long-running operation + * that could potentially be attempted in parallel by multiple requests should + * try to acquire a lock before proceeding. By obtaining a lock, one request + * notifies any other requests that a specific operation is in progress which + * must not be executed in parallel. + * + * To use this API, pick a unique name for the lock. A sensible choice is the + * name of the function performing the operation. A very simple example use of + * this API: + * @code + * function mymodule_long_operation() { + * if (\Drupal::lock()->acquire('mymodule_long_operation')) { + * // Do the long operation here. + * // ... + * \Drupal::lock()->release('mymodule_long_operation'); + * } + * } + * @endcode + * + * If a function acquires a lock it should always release it when the + * operation is complete by calling \Drupal::lock()->release(), as in the + * example. + * + * A function that has acquired a lock may attempt to renew a lock (extend the + * duration of the lock) by calling \Drupal::lock()->acquire() again during the + * operation. + * Failure to renew a lock is indicative that another request has acquired + * the lock, and that the current operation may need to be aborted. + * + * If a function fails to acquire a lock it may either immediately return, or + * it may call \Drupal::lock()->wait() if the rest of the current page request + * requires that the operation in question be complete. After + * \Drupal::lock()->wait() returns, the function may again attempt to acquire + * the lock, or may simply allow the page request to proceed on the assumption + * that a parallel request completed the operation. + * + * \Drupal::lock()->acquire() and \Drupal::lock()->wait() will automatically + * break (delete) a lock whose duration has exceeded the timeout specified when + * it was acquired. + */ + +/** * Lock backend interface. + * + * @ingroup lock */ interface LockBackendInterface { diff --git a/core/lib/Drupal/Core/Lock/NullLockBackend.php b/core/lib/Drupal/Core/Lock/NullLockBackend.php index bd59888..7a37cd4 100644 --- a/core/lib/Drupal/Core/Lock/NullLockBackend.php +++ b/core/lib/Drupal/Core/Lock/NullLockBackend.php @@ -12,6 +12,8 @@ * * This implementation won't actually lock anything and will always succeed on * lock attempts. + * + * @ingroup lock */ class NullLockBackend implements LockBackendInterface {