diff --git a/Sources/NIO/EventLoop.swift b/Sources/NIO/EventLoop.swift index e27e4fca1..bde61bb02 100644 --- a/Sources/NIO/EventLoop.swift +++ b/Sources/NIO/EventLoop.swift @@ -69,7 +69,7 @@ extension EventLoop { // TODO: Implement scheduling tasks in the future (a.k.a ScheduledExecutoreService final class SelectableEventLoop : EventLoop { private let selector: Sockets.Selector - private var thread: Thread? + private var thread: pthread_t? private var tasks: [() -> ()] private let tasksLock = Lock() private var closed = false @@ -110,7 +110,7 @@ final class SelectableEventLoop : EventLoop { } var inEventLoop: Bool { - return Thread.current.isEqual(thread) + return pthread_self() == thread } func execute(task: @escaping () -> ()) { @@ -123,7 +123,7 @@ final class SelectableEventLoop : EventLoop { } func run() throws { - thread = Thread.current + thread = pthread_self() defer { // Ensure we reset the running Thread when this methods returns. thread = nil diff --git a/Sources/NIO/Future.swift b/Sources/NIO/Future.swift index b0873a1b4..953a83bd7 100644 --- a/Sources/NIO/Future.swift +++ b/Sources/NIO/Future.swift @@ -12,7 +12,6 @@ // //===----------------------------------------------------------------------===// -import Foundation import ConcurrencyHelpers @@ -140,7 +139,7 @@ private struct CallbackList: ExpressibleByArrayLiteral { * If you just want to get a value back after running something on another thread, use `Future.async()` * If you already have a value and need a Future<> object to plug into some other API, create an already-resolved object with `Future(result:)` */ -public class Promise { +public final class Promise { public let futureResult: Future /** @@ -263,7 +262,7 @@ public class Promise { TODO: Provide a tracing facility. It would be nice to be able to set '.debugTrace = true' on any Future or Promise and have every subsequent chained Future report the success result or failure error. That would simplify some debugging scenarios. */ -public class Future: Hashable { +public final class Future { fileprivate var value: FutureValue = .incomplete fileprivate let _fullfilled = Atomic(value: false) fileprivate let checkForPossibleDeadlock: Bool @@ -298,10 +297,7 @@ public class Future: Hashable { /// Callbacks that should be run when this Future<> gets a value. /// These callbacks may give values to other Futures; if that happens, they return any callbacks from those Futures so that we can run the entire chain from the top without recursing. fileprivate var callbacks: CallbackList = CallbackList() - - // Each instance gets a random hash value - public lazy var hashValue = NSUUID().hashValue - + fileprivate init(eventLoop: EventLoop, checkForPossibleDeadlock: Bool) { self.eventLoop = eventLoop self.checkForPossibleDeadlock = checkForPossibleDeadlock @@ -515,7 +511,7 @@ public extension Future { * of results. If either one fails, the combined Future will fail. */ public func and(_ other: Future) -> Future<(T,U)> { - let andlock = NSLock() + let andlock = Lock() let promise = Promise<(T,U)>(eventLoop: eventLoop, checkForPossibleDeadlock: checkForPossibleDeadlock) var tvalue: T? var uvalue: U?