-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
54 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 9 additions & 7 deletions
16
DXFeedFramework/Utils/ConcurentWeakSet.swift → ...ework/Utils/ConcurrentWeakHashTable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,39 @@ | ||
// | ||
// ConcurentWeakSet.swift | ||
// ConcurrentWeakHashTable.swift | ||
// DXFeedFramework | ||
// | ||
// Created by Aleksey Kosylo on 29.09.23. | ||
// | ||
|
||
import Foundation | ||
|
||
public class ConcurrentWeakSet<T: AnyObject> { | ||
private var set: NSHashTable<T> = .weakObjects() | ||
public class ConcurrentWeakHashTable<T> { | ||
internal var set: NSHashTable<AnyObject> = .weakObjects() | ||
private let accessQueue = DispatchQueue(label: "com.dxfeed.set_nshashtable", attributes: .concurrent) | ||
|
||
public var count: Int { | ||
reader { $0.count } | ||
} | ||
|
||
public func insert(_ newMember: T) { | ||
writer { $0.add(newMember) } | ||
writer { | ||
$0.add(newMember as AnyObject) | ||
} | ||
} | ||
|
||
public func remove(_ member: T) { | ||
writer { $0.remove(member) } | ||
writer { $0.remove(member as AnyObject) } | ||
} | ||
|
||
public func removeAll() { | ||
writer { $0.removeAllObjects() } | ||
} | ||
|
||
public func reader<U>(_ block: (NSHashTable<T>) throws -> U) rethrows -> U { | ||
public func reader<U>(_ block: (NSHashTable<AnyObject>) throws -> U) rethrows -> U { | ||
try accessQueue.sync { try block(set) } | ||
} | ||
|
||
public func writer(_ block: @escaping (inout NSHashTable<T>) -> Void) { | ||
public func writer(_ block: @escaping (inout NSHashTable<AnyObject>) -> Void) { | ||
accessQueue.async(flags: .barrier) { block(&self.set) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,3 @@ class ConnectEventListener: AbstractEventListener { | |
} | ||
} | ||
} | ||
|
||
|
||
|