-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
1 parent
f6df347
commit 78fe8e8
Showing
3 changed files
with
38 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright AudioKit. All Rights Reserved. Revision History at http://github.com/AudioKit/AudioKit/ | ||
|
||
import Foundation | ||
|
||
class TapRegistry: @unchecked Sendable { | ||
|
||
struct WeakTap { | ||
weak var tap: Tap? | ||
|
||
init(tap: Tap?) { | ||
self.tap = tap | ||
} | ||
} | ||
|
||
let tapRegistryLock = NSLock() | ||
|
||
var tapRegistry: [ObjectIdentifier: [WeakTap]] = [:] | ||
|
||
func getTapsFor(node: Node) -> [Tap] { | ||
tapRegistryLock.withLock { | ||
(tapRegistry[ObjectIdentifier(node)] ?? []).compactMap { $0.tap } | ||
} | ||
} | ||
|
||
func add(tap: Tap, for node: Node) { | ||
tapRegistryLock.withLock { | ||
if tapRegistry.keys.contains(ObjectIdentifier(node)) { | ||
tapRegistry[ObjectIdentifier(node)]?.append(WeakTap(tap: tap)) | ||
} else { | ||
tapRegistry[ObjectIdentifier(node)] = [WeakTap(tap: tap)] | ||
} | ||
} | ||
} | ||
|
||
static let shared = TapRegistry() | ||
} |