Skip to content

Commit 39c4f00

Browse files
committed
Sync waiter array. Fixes #8
1 parent 6278346 commit 39c4f00

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Sources/InterposeKit/InterposeKit.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ extension Interpose {
239239

240240
// Immediately try to execute task. If not there, install waiter.
241241
if try tryExecute() == false {
242-
InterposeWatcher.globalWatchers.append(self)
242+
InterposeWatcher.append(waiter: self)
243243
}
244244
}
245245

@@ -257,12 +257,18 @@ extension Interpose {
257257
// dyld C function cannot capture class context so we pack it in a static struct.
258258
private struct InterposeWatcher {
259259
// Global list of waiters; can be multiple per class
260-
fileprivate static var globalWatchers: [Interpose.Waiter] = {
260+
private static var globalWatchers: [Interpose.Waiter] = {
261261
// Register after Swift global registers to not deadlock
262262
DispatchQueue.main.async { InterposeWatcher.installGlobalImageLoadWatcher() }
263263
return []
264264
}()
265265

266+
fileprivate static func append(waiter: Interpose.Waiter) {
267+
InterposeWatcher.globalWatcherQueue.sync {
268+
globalWatchers.append(waiter)
269+
}
270+
}
271+
266272
// Register hook when dyld loads an image
267273
private static let globalWatcherQueue = DispatchQueue(label: "com.steipete.global-image-watcher")
268274
private static func installGlobalImageLoadWatcher() {

0 commit comments

Comments
 (0)