Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add locking to File interface #87

Merged
merged 17 commits into from
Jan 9, 2025
Merged

Add locking to File interface #87

merged 17 commits into from
Jan 9, 2025

Conversation

trowski
Copy link
Member

@trowski trowski commented Dec 8, 2024

This adds three new methods to the File interface: lock, unlock, and getLockMode. As the names imply, these functions provide a non-blocking method obtaining and releasing a shared or exclusive lock on the file. The mode is provided by a new enum, LockMode with two cases: Shared and Exclusive. lock tries to obtain the lock in a loop using an exponential-backoff until a lock is obtained or the optional cancellation is cancelled. getLockMode returns the current lock mode if the file has been locked or null otherwise.

I've refactored FileMutex and KeyedFileMutex to use these two new async methods.

I think is a better option than #86, however it will require a new major version since the File interface has been modified. I don't consider this a blocker, as most components will be able to require 3.x or 4.x.

DO NOT merge into 3.x, we'll need make a 4.x branch if this is merged.

@trowski trowski changed the title Add lock and unlock to File interface Add locking to File interface Dec 8, 2024
src/FileMutex.php Outdated Show resolved Hide resolved
src/Internal/FileTask.php Outdated Show resolved Hide resolved
@trowski
Copy link
Member Author

trowski commented Dec 10, 2024

Updated to also add tryLock to the File interface which may be used to make a non-blocking attempt to lock the file, immediately returning true if the lock is obtained or false if not.

@trowski trowski requested a review from kelunik December 10, 2024 15:55
src/Driver/BlockingFile.php Outdated Show resolved Hide resolved
src/Driver/ParallelFile.php Outdated Show resolved Hide resolved
@trowski trowski changed the base branch from 3.x to 4.x January 9, 2025 04:30
@trowski trowski merged commit 5b6d389 into 4.x Jan 9, 2025
12 checks passed
@kelunik kelunik deleted the locks branch January 9, 2025 09:55
This was referenced Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants