Skip to content

Commit 20df19f

Browse files
author
Julian Lettner
committed
Move TSan function lookup out of the common path
Move TSan function lookup via `dlsym()` out of the common path. The TSan runtime will now call `__tsan_on_initialize()` which we can use to initialize the TSan functions in the Swift runtime. This avoids paying the cost of `dlsym()` in the common, non-TSan case. Depends on: https://reviews.llvm.org/D98810 rdar://75493372
1 parent 172e136 commit 20df19f

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

stdlib/public/Concurrency/ThreadSanitizer.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13-
// Thread Sanitizer support for the Swift Task runtime
13+
// Thread Sanitizer support for the Swift Task runtime.
1414
//
1515
//===----------------------------------------------------------------------===//
1616

@@ -34,30 +34,22 @@ TSanFunc *loadSymbol(const char *name) {
3434
return (TSanFunc *)dlsym(RTLD_DEFAULT, name);
3535
#endif
3636
}
37-
38-
swift::swift_once_t initOnceToken;
39-
void initializeThreadSanitizer(void *unused) {
40-
tsan_acquire = loadSymbol("__tsan_acquire");
41-
tsan_release = loadSymbol("__tsan_release");
42-
}
4337
} // anonymous namespace
4438

4539
void swift::_swift_tsan_acquire(void *addr) {
46-
swift_once(&initOnceToken, initializeThreadSanitizer, nullptr);
4740
if (tsan_acquire) {
4841
tsan_acquire(addr);
4942
}
5043
}
5144

5245
void swift::_swift_tsan_release(void *addr) {
53-
swift_once(&initOnceToken, initializeThreadSanitizer, nullptr);
5446
if (tsan_release) {
5547
tsan_release(addr);
5648
}
5749
}
5850

5951
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(c)
60-
void swift_task_set_tsan_hooks(TSanFunc *acquire, TSanFunc *release) {
61-
tsan_acquire = acquire;
62-
tsan_release = release;
52+
void __tsan_on_initialize() {
53+
tsan_acquire = loadSymbol("__tsan_acquire");
54+
tsan_release = loadSymbol("__tsan_release");
6355
}

0 commit comments

Comments
 (0)