Skip to content

Commit 9c1d0a4

Browse files
docs(lock): improve ILockingProvider documentation
Signed-off-by: Josh <josh.t.richards@gmail.com>
1 parent e88740d commit 9c1d0a4

1 file changed

Lines changed: 56 additions & 12 deletions

File tree

lib/public/Lock/ILockingProvider.php

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,98 @@
1010
namespace OCP\Lock;
1111

1212
/**
13-
* This interface allows locking and unlocking filesystem paths
13+
* Contract for providers of shared and exclusive locks for server resources.
1414
*
15-
* This interface should be used directly and not implemented by an application.
16-
* The implementation is provided by the server.
15+
* This low-level interface provides the short-lived locks used for concurrency
16+
* control by Nextcloud storage implementations and, through them, by the Files
17+
* Node and View APIs.
18+
*
19+
* While primarily used by storage implementations, this interface is generic
20+
* and may also coordinate access to other server resources.
21+
*
22+
* This is an underlying primitive, not the high-level VFS API used for locking
23+
* filesystem paths during normal Files Node or View operations.
24+
*
25+
* This interface is distinct from the OCP\Files\Lock APIs, which provide
26+
* user, application, and collaborative-editor locks for files.
1727
*
1828
* @since 8.1.0
1929
*/
2030
interface ILockingProvider {
2131
/**
32+
* A shared lock. Multiple shared locks may coexist, but they prevent an
33+
* exclusive lock from being acquired.
34+
*
2235
* @since 8.1.0
2336
*/
2437
public const LOCK_SHARED = 1;
38+
2539
/**
40+
* An exclusive lock. It prevents shared and exclusive locks from being
41+
* acquired.
42+
*
2643
* @since 8.1.0
2744
*/
2845
public const LOCK_EXCLUSIVE = 2;
2946

3047
/**
31-
* @psalm-param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type
48+
* Check whether a lock of the requested type exists for a resource.
49+
*
50+
* This does not determine whether acquiring the requested type would
51+
* succeed. For example, an existing shared lock prevents an exclusive
52+
* acquisition, while this method returns false for LOCK_EXCLUSIVE.
53+
*
54+
* @param string $path Identifier of the resource to check.
55+
* @param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type Lock type to check.
56+
* @return bool True when a lock of the requested type exists.
3257
* @since 8.1.0
3358
*/
3459
public function isLocked(string $path, int $type): bool;
3560

3661
/**
37-
* @psalm-param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type
38-
* @param ?string $readablePath A human-readable path to use in error messages, since 20.0.0
39-
* @throws LockedException
62+
* Acquire a shared or exclusive lock for a resource.
63+
*
64+
* A shared lock cannot be acquired while an exclusive lock exists. An
65+
* exclusive lock cannot be acquired while any lock exists.
66+
*
67+
* @param string $path Identifier of the resource to lock.
68+
* @param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type Lock type to acquire.
69+
* @param ?string $readablePath Optional human-readable representation of
70+
* `$path` to include in error messages.
71+
* @throws LockedException If the requested lock cannot be acquired.
4072
* @since 8.1.0
4173
*/
4274
public function acquireLock(string $path, int $type, ?string $readablePath = null): void;
4375

4476
/**
45-
* @psalm-param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type
77+
* Release one acquisition of the requested lock type for a resource.
78+
*
79+
* Repeated shared-lock acquisitions must be released separately.
80+
*
81+
* @param string $path Identifier of the resource to unlock.
82+
* @param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $type Lock type to release.
4683
* @since 8.1.0
4784
*/
4885
public function releaseLock(string $path, int $type): void;
4986

5087
/**
51-
* Change the target type of an existing lock
88+
* Convert an existing lock to another type.
89+
*
90+
* Converting a shared lock to an exclusive lock succeeds only when the
91+
* shared lock is the only shared lock. An exclusive lock can be converted
92+
* to a shared lock.
5293
*
53-
* @psalm-param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $targetType
54-
* @throws LockedException
94+
* @param string $path Identifier of the resource whose lock to change.
95+
* @param self::LOCK_SHARED|self::LOCK_EXCLUSIVE $targetType Lock type to
96+
* convert to.
97+
* @throws LockedException If the existing lock cannot be converted.
5598
* @since 8.1.0
5699
*/
57100
public function changeLock(string $path, int $targetType): void;
58101

59102
/**
60-
* Release all lock acquired by this instance
103+
* Release all locks acquired and tracked by this provider instance.
104+
*
61105
* @since 8.1.0
62106
*/
63107
public function releaseAll(): void;

0 commit comments

Comments
 (0)