fixes for Swift 6 and threading concerns
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
import Foundation
|
||||
import Darwin
|
||||
import Dispatch
|
||||
@testable import LyrebirdSynth
|
||||
@@ -27,13 +28,19 @@ struct RTThreadIdentityTests {
|
||||
#expect(RTThreadIdentity.isCurrentThreadRT == false)
|
||||
|
||||
// Mark a *different* pthread, confirm via that thread's own read.
|
||||
let markerSawRT: Bool = await withCheckedContinuation { continuation in
|
||||
let queue: DispatchQueue = DispatchQueue(label: "RTThreadIdentityTests.marker")
|
||||
queue.async {
|
||||
// Use a one-shot detached `Thread` (NOT a `DispatchQueue`): a GCD worker pthread is
|
||||
// recycled into the shared pool still carrying the RT marker, which can then
|
||||
// false-trip `_lyrebirdAssertNotOnRTThread` in a later `.compute()` test the pool
|
||||
// hands the same thread. A detached `Thread` terminates its pthread when the block
|
||||
// returns, so the marker cannot leak; we also clear it defensively.
|
||||
let markerSawRT: Bool = await withCheckedContinuation { (continuation: CheckedContinuation<Bool, Never>) in
|
||||
let thread: Thread = Thread {
|
||||
RTThreadIdentity.markCurrentThreadAsRT()
|
||||
let observed: Bool = RTThreadIdentity.isCurrentThreadRT
|
||||
lyrebirdClearRTMarkAfterTestRender()
|
||||
continuation.resume(returning: observed)
|
||||
}
|
||||
thread.start()
|
||||
}
|
||||
#expect(markerSawRT == true)
|
||||
|
||||
@@ -43,14 +50,16 @@ struct RTThreadIdentityTests {
|
||||
}
|
||||
|
||||
@Test func markIsIdempotent() async {
|
||||
let observedMarked: Bool = await withCheckedContinuation { continuation in
|
||||
let queue: DispatchQueue = DispatchQueue(label: "RTThreadIdentityTests.idempotent")
|
||||
queue.async {
|
||||
let observedMarked: Bool = await withCheckedContinuation { (continuation: CheckedContinuation<Bool, Never>) in
|
||||
let thread: Thread = Thread {
|
||||
RTThreadIdentity.markCurrentThreadAsRT()
|
||||
RTThreadIdentity.markCurrentThreadAsRT()
|
||||
RTThreadIdentity.markCurrentThreadAsRT()
|
||||
continuation.resume(returning: RTThreadIdentity.isCurrentThreadRT)
|
||||
let observed: Bool = RTThreadIdentity.isCurrentThreadRT
|
||||
lyrebirdClearRTMarkAfterTestRender()
|
||||
continuation.resume(returning: observed)
|
||||
}
|
||||
thread.start()
|
||||
}
|
||||
#expect(observedMarked == true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user