swift-nio
swift-nio copied to clipboard
Update our locks to use Synchronization.Mutex or os_unfair_lock
Now that we require Swift 6.0, update LockStorage to use Synchronization.Mutex or os_unfair_lock
Motivation:
Simplify and optimize NIOLock and NIOLockedValueBox on every platform
Modifications:
- Moved all
pthread_mutex_tandSRWLOCKcode intolock.swift, to support our condition variable type - Rebuild
LockStoragearoundSynchronization.Mutexon most platforms - On Darwin, rebuild around
os_unfair_lockinstead to support back deployment - On Darwin, the pointer technique is copied from
ManagedAtomicfromswift-atomics
Result:
- Much simpler code
- Better or equal performance
Mutex has platform availability guards:
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
@frozen public struct Mutex<Value> : ~Copyable where Value : ~Copyable {
How do we want to adopt that without increasing our platform requirements?
Only adopt it on non-Apple platforms.