-
Notifications
You must be signed in to change notification settings - Fork 11
Locker v2 #5
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
Locker v2 #5
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR modernizes the locking API by removing legacy functions and error returns while leveraging Go 1.19 atomics and introducing an RWLocker with associated sync.Locker adapters. Key changes include removal of New() and ErrNoSuchLock, updating tests to use zero values, and refactoring the unlock functions for both Locker and RWLocker for consistency with standard library panic behavior.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| rwlocker_test.go | Tests for RWLocker functionality and concurrency management. |
| rwlocker.go | Implementation of RWLocker with atomic waiters and lock deletion logic. |
| locker_test.go | Tests updated to use zero value Locker instead of New(). |
| locker.go | Refactored Locker implementation; removed error return from Unlock. |
| go.mod | Updates module name to v2 and bumps Go version to 1.19 |
7bba17f to
7d2d391
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR releases Locker v2 by removing legacy APIs (including New() and ErrNoSuchLock) and modernizing the code to use Go 1.19 atomics, while adding an RWLocker for read–write locks and sync.Locker adapters.
- Removed the old Locker implementation and its associated error and constructor functions.
- Introduced RWMutexMap and updated MutexMap to use atomic counters and a zero–value valid pattern.
- Updated go.mod and CI workflow to require Go 1.19 and use the latest GitHub Actions.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| rwmutexmap_test.go | Added tests for the new RWMutexMap locking behavior. |
| rwmutexmap.go | Implements the RWMutexMap using atomics with helper functions for locking/unlock. |
| mutexmap_test.go | Updated tests for MutexMap (removal of New() and atomic counter checks). |
| mutexmap.go | Implements MutexMap using atomics and sync.Pool for lock counter management. |
| locker.go | Removed legacy Locker code as part of breaking changes. |
| go.mod | Updated module path and Go version to 1.19. |
| .github/workflows/test.yml | Updated workflow settings to use new checkout and Go setup actions. |
Breaking changes: - The minimum Go version is go1.19 - Locker has been replaced with the generic MutexMap[T] - The result parameter to (*MutexMap[T]).Unlock() has been dropped. Instead the application will crash with the same fatal run-time error as calling (sync.Mutex).Unlock() on an unlocked mutex. - ErrNoSuchLock has been removed. - New() has been removed. The zero value is valid. Modernize the codebase by taking advantage of Go 1.18 generics and Go 1.19 atomics. Add a sync.Locker interface adapter for MutexMap. Signed-off-by: Cory Snider <csnider@mirantis.com>
The benchmarks show a reduction in allocs without significant performance regression. Signed-off-by: Cory Snider <csnider@mirantis.com>
|
My RWMutex implementation is bugged. I'll submit it in a separate PR. |
Breaking changes:
Lockerhas been replaced with the genericMutexMap[T](*MutexMap[T]).Unlock()has been dropped. Instead the application will crash with the same fatal run-time error as calling(sync.Mutex).Unlock()on an unlocked mutex.ErrNoSuchLockhas been removed.New()has been removed. The zero value is valid.Modernize the codebase by taking advantage of Go 1.18 generics and Go 1.19 atomics.
Add anAddRWMutexMapfor read-write locks.sync.Lockerinterface adapters forMutexMapandRWMutexMap.