Revert "[Distributed] workaround for LocalTestingDAS crashes;"

This reverts commit bcd0f64e91.
This commit is contained in:
Konrad `ktoso` Malawski
2022-05-08 18:26:07 +09:00
parent 1e489d6c0b
commit 1675669e43
5 changed files with 661 additions and 668 deletions

View File

@@ -43,7 +43,7 @@ public final class LocalTestingDistributedActorSystem: DistributedActorSystem, @
public init() {}
public func resolve<Act>(id: ActorID, as actorType: Act.Type)
throws -> Act? where Act: DistributedActor {
throws -> Act? where Act: DistributedActor, Act.ID == ActorID {
guard let anyActor = self.activeActorsLock.withLock({ self.activeActors[id] }) else {
throw LocalTestingDistributedActorSystemError(message: "Unable to locate id '\(id)' locally")
}
@@ -54,7 +54,7 @@ public final class LocalTestingDistributedActorSystem: DistributedActorSystem, @
}
public func assignID<Act>(_ actorType: Act.Type) -> ActorID
where Act: DistributedActor {
where Act: DistributedActor, Act.ID == ActorID {
let id = self.idProvider.next()
self.assignedIDsLock.withLock {
self.assignedIDs.insert(id)
@@ -63,8 +63,7 @@ public final class LocalTestingDistributedActorSystem: DistributedActorSystem, @
}
public func actorReady<Act>(_ actor: Act)
where Act: DistributedActor,
Act.ID == ActorID {
where Act: DistributedActor, Act.ID == ActorID {
guard self.assignedIDsLock.withLock({ self.assignedIDs.contains(actor.id) }) else {
fatalError("Attempted to mark an unknown actor '\(actor.id)' ready")
}
@@ -246,10 +245,27 @@ fileprivate class _Lock {
private let underlying: UnsafeMutablePointer<pthread_mutex_t>
#endif
init() {
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
self.underlying.initialize(to: os_unfair_lock())
#elseif os(Windows)
self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
InitializeSRWLock(self.underlying)
#elseif os(WASI)
// WASI environment has only a single thread
#else
self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
guard pthread_mutex_init(self.underlying, nil) == 0 else {
fatalError("pthread_mutex_init failed")
}
#endif
}
deinit {
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
// `os_unfair_lock`s do not need to be explicitly destroyed
#elseif os(Windows)
#elseif os(Windows)
// `SRWLOCK`s do not need to be explicitly destroyed
#elseif os(WASI)
// WASI environment has only a single thread
@@ -265,21 +281,6 @@ fileprivate class _Lock {
#endif
}
init() {
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
#elseif os(Windows)
self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
InitializeSRWLock(self.underlying)
#elseif os(WASI)
// WASI environment has only a single thread
#else
self.underlying = UnsafeMutablePointer.allocate(capacity: 1)
guard pthread_mutex_init(self.underlying, nil) == 0 else {
fatalError("pthread_mutex_init failed")
}
#endif
}
@discardableResult
func withLock<T>(_ body: () -> T) -> T {