Use UInt instead of ObjectIdentifier in promiseCreationStore (#1411)

* Use UInt instead of ObjectIdentifier in promiseCreationStore

* defined obfuscatePointerValue method
This commit is contained in:
Shekhar Rajak authored and GitHub committed 2020-02-24 17:01:16 +00:00
1 parent 2c555d144a
commit 58a80c300e
1 file changed
+11 -3
+11 -3
View File
@@ -87,20 +87,20 @@ internal final class SelectableEventLoop: EventLoop {
/// Creates a new `SelectableEventLoop` instance that is tied to the given `pthread_t`.
private let promiseCreationStoreLock = Lock()
private var _promiseCreationStore: [ObjectIdentifier: (file: StaticString, line: UInt)] = [:]
private var _promiseCreationStore: [UInt: (file: StaticString, line: UInt)] = [:]
@usableFromInline
internal func promiseCreationStoreAdd<T>(future: EventLoopFuture<T>, file: StaticString, line: UInt) {
precondition(_isDebugAssertConfiguration())
self.promiseCreationStoreLock.withLock {
self._promiseCreationStore[ObjectIdentifier(future)] = (file: file, line: line)
self._promiseCreationStore[self.obfuscatePointerValue(future)] = (file: file, line: line)
}
}
internal func promiseCreationStoreRemove<T>(future: EventLoopFuture<T>) -> (file: StaticString, line: UInt) {
precondition(_isDebugAssertConfiguration())
return self.promiseCreationStoreLock.withLock {
self._promiseCreationStore.removeValue(forKey: ObjectIdentifier(future))!
self._promiseCreationStore.removeValue(forKey: self.obfuscatePointerValue(future))!
}
}
@@ -301,6 +301,14 @@ internal final class SelectableEventLoop: EventLoop {
return .blockUntilTimeout(nextReady)
}
}
private func obfuscatePointerValue<T>(_ future: EventLoopFuture<T>) -> UInt {
// Note:
// 1. 0xbf15ca5d is randomly picked such that it fits into both 32 and 64 bit address spaces
// 2. XOR with 0xbf15ca5d so that Memory Graph Debugger and other memory debugging tools
// won't see it as a reference.
return UInt(bitPattern: ObjectIdentifier(future)) ^ 0xbf15ca5d
}
/// Start processing I/O and tasks for this `SelectableEventLoop`. This method will continue running (and so block) until the `SelectableEventLoop` is closed.
internal func run() throws {