Skip to content

Use os_unfair_lock on Darwin when available.#942

Merged
grynspan merged 5 commits into
mainfrom
jgrynspan/use-os-unfair-lock
Feb 6, 2025
Merged

Use os_unfair_lock on Darwin when available.#942
grynspan merged 5 commits into
mainfrom
jgrynspan/use-os-unfair-lock

Conversation

@grynspan

@grynspan grynspan commented Feb 5, 2025

Copy link
Copy Markdown
Contributor

This PR refactors the Locked type to be generic over the type of lock it uses, allowing us to adopt os_unfair_lock in most places, but also allowing us to use other lock types as needed (i.e. pthread_mutex_t in WaitFor.swift if libdispatch is unavailable.)

Under -O, locking and unlocking is fully inlined, while initialization (which is relatively rare) is partially, but not completely, inlined.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

This PR refactors the `Locked` type to be generic over the type of lock it uses,
allowing us to adopt `os_unfair_lock` in most places, but also allowing us to
use other lock types as needed (i.e. `pthread_mutex_t` in WaitFor.swift if
libdispatch is unavailable.)

Under `-O`, locking and unlocking is fully inlined, while initialization (which
is relatively rare) is partially, but not completely, inlined.
@grynspan grynspan added enhancement New feature or request concurrency 🔀 Swift concurrency/sendability issues darwin 🍎 macOS, iOS, watchOS, tvOS, and visionOS support performance 🏎️ Performance issues labels Feb 5, 2025
@grynspan grynspan added this to the Swift 6.x milestone Feb 5, 2025
@grynspan grynspan self-assigned this Feb 5, 2025
@grynspan

grynspan commented Feb 5, 2025

Copy link
Copy Markdown
Contributor Author

@swift-ci test

@grynspan

grynspan commented Feb 5, 2025

Copy link
Copy Markdown
Contributor Author

@swift-ci test

@grynspan

grynspan commented Feb 5, 2025

Copy link
Copy Markdown
Contributor Author

@swift-ci test

Comment thread Sources/Testing/Support/Locked.swift Outdated
Comment thread Sources/Testing/Support/Locked.swift Outdated
Co-authored-by: Stuart Montgomery <smontgomery@apple.com>
@grynspan grynspan requested a review from stmontgomery February 5, 2025 21:14
@grynspan

grynspan commented Feb 5, 2025

Copy link
Copy Markdown
Contributor Author

@swift-ci test

@grynspan

grynspan commented Feb 5, 2025

Copy link
Copy Markdown
Contributor Author

@swift-ci test

Comment thread Sources/Testing/ExitTests/WaitFor.swift
@grynspan grynspan merged commit 63eb1d9 into main Feb 6, 2025
@grynspan grynspan deleted the jgrynspan/use-os-unfair-lock branch February 6, 2025 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

concurrency 🔀 Swift concurrency/sendability issues darwin 🍎 macOS, iOS, watchOS, tvOS, and visionOS support enhancement New feature or request performance 🏎️ Performance issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants