| Defined | src/filesystem/PhutilLock.php:30 |
|---|---|
| Group | Filesystem |
Base class for locks, like file locks.
libphutil provides a concrete lock in PhutilFileLock.
$lock->lock(); do_contentious_things(); $lock->unlock();
If the lock can't be acquired because it is already held, PhutilLockException is thrown. Other exceptions indicate permanent failure unrelated to locking.
When extending this class, you should call getLock() to look up an existing lock object, and registerLock() when objects are constructed to register for automatic unlock on shutdown.
| parameters | string | $name | Globally unique lock name. |
| return | this |
Build a new lock, given a lock name. The name should be globally unique across all locks.
| parameters | float | $wait | Seconds to block waiting for the lock. |
| return | void |
Acquires the lock, or throws PhutilLockException if it fails.
| return | void |
Releases the lock.
| parameters | string | $name | Lock name. |
| return | wild |
Get a named lock, if it has been registered.
| return | string | Globally unique lock name, across all locks. |
Returns a globally unique name for this lock.
| return | bool | True if the lock is held. |
Determine if the lock is currently held.
| parameters | float | $wait | Seconds to block waiting for the lock. By default, do not block. |
| return | this |
Acquire the lock. If lock acquisition fails because the lock is held by another process, throws PhutilLockException. Other exceptions indicate that lock acquisition has failed for reasons unrelated to locking.
If the lock is already held by this process, this method throws. You can test the lock status with isLocked().
| parameters | PhutilLock | $lock | Lock to register. |
| return | wild |
Register a lock for cleanup when the process exits.
| return | this |
Release the lock. Throws an exception on failure, e.g. if the lock is not currently held.
| return | void |
On shutdown, we release all the locks. You should not call this method directly. Use unlock() to release individual locks.