Skip to content

Conversation

@corhere
Copy link
Contributor

@corhere corhere commented May 9, 2025

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 an RWMutexMap for read-write locks. Add sync.Locker interface adapters for MutexMap and RWMutexMap.

@corhere corhere requested review from Copilot and thaJeztah May 9, 2025 20:01
Copy link

Copilot AI left a 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

@corhere corhere marked this pull request as draft May 12, 2025 15:11
@corhere corhere force-pushed the version-two branch 2 times, most recently from 7bba17f to 7d2d391 Compare May 22, 2025 16:42
@corhere corhere marked this pull request as ready for review May 22, 2025 16:43
@corhere corhere marked this pull request as draft May 22, 2025 16:48
@corhere corhere requested a review from Copilot May 22, 2025 17:25
Copy link

Copilot AI left a 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.

@corhere corhere marked this pull request as ready for review May 22, 2025 17:32
corhere added 2 commits May 22, 2025 16:21
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>
@corhere
Copy link
Contributor Author

corhere commented May 22, 2025

My RWMutex implementation is bugged. I'll submit it in a separate PR.

@corhere corhere merged commit dc2460c into moby:main May 22, 2025
4 checks passed
@thompson-shaun thompson-shaun moved this from New to Complete in 🔦 Maintainer spotlight May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants