Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Sources/ThreadLocal/ThreadLocal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class ThreadLocal<Value>: Sendable {
return unmanaged.takeUnretainedValue()
}

@_unavailableFromAsync
@available(*, noasync)
public init(_deallocator deallocator: Deallocator = .default) {
_key = pthread_key_t()
_deallocator = deallocator
Expand All @@ -51,14 +51,14 @@ public final class ThreadLocal<Value>: Sendable {
precondition(status == 0, "pthread_key_create failed with status code \(status)")
}

@available(*, noasync)
@inlinable
@_unavailableFromAsync
func _makeBox(_ value: Value) -> _Box {
_Box(_value: value, deallocator: _deallocator)
}

@available(*, noasync)
@inlinable
@_unavailableFromAsync
public func _get(default: @autoclosure () -> Value) -> Value {
if let value = _box?._value {
return value
Expand All @@ -69,8 +69,8 @@ public final class ThreadLocal<Value>: Sendable {
}
}

@available(*, noasync)
@inlinable
@_unavailableFromAsync
public func _set(_ newValue: Value?) {
let unmanaged = pthread_getspecific(_key).map {
Unmanaged<_Box>.fromOpaque($0)
Expand Down
6 changes: 3 additions & 3 deletions Sources/ThreadLocalMacros/ThreadLocalMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ extension ThreadLocalMacro: AccessorMacro {
}
let getAccessor: AccessorDeclSyntax = if let initializer = binding.initializer {
"""
get {
@available(*, noasync) get {
_\(identifier)._get(default: \(initializer.value))
}
"""
} else {
"""
get {
@available(*, noasync) get {
_\(identifier)._get(default: nil)
}
"""
}
let setAccessor: AccessorDeclSyntax =
"""
set {
@available(*, noasync) set {
_\(identifier)._set(newValue)
}
"""
Expand Down
20 changes: 10 additions & 10 deletions Tests/ThreadLocalTests/ThreadLocalMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ struct ThreadLocalMacroTests {
expandedSource:
"""
static var counter: Int {
get {
@available(*, noasync) get {
_counter._get(default: 0)
}
set {
@available(*, noasync) set {
_counter._set(newValue)
}
}
Expand All @@ -55,10 +55,10 @@ struct ThreadLocalMacroTests {
expandedSource:
"""
@inlinable static var counter: Int {
get {
@available(*, noasync) get {
_counter._get(default: 0)
}
set {
@available(*, noasync) set {
_counter._set(newValue)
}
}
Expand All @@ -79,10 +79,10 @@ struct ThreadLocalMacroTests {
expandedSource:
"""
static var ctx: OpaquePointer {
get {
@available(*, noasync) get {
_ctx._get(default: ZSTD_createCCtx())
}
set {
@available(*, noasync) set {
_ctx._set(newValue)
}
}
Expand All @@ -104,10 +104,10 @@ struct ThreadLocalMacroTests {
expandedSource:
"""
public static var counter: Int {
get {
@available(*, noasync) get {
_counter._get(default: 0)
}
set {
@available(*, noasync) set {
_counter._set(newValue)
}
}
Expand Down Expand Up @@ -148,10 +148,10 @@ struct ThreadLocalMacroTests {
expandedSource:
"""
static var counter: Int {
get {
@available(*, noasync) get {
_counter._get(default: 0)
}
set {
@available(*, noasync) set {
_counter._set(newValue)
}
}
Expand Down
Loading