|
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 | //
|
13 |
| -// Thread Sanitizer support for the Swift Task runtime |
| 13 | +// Thread Sanitizer support for the Swift Task runtime. |
14 | 14 | //
|
15 | 15 | //===----------------------------------------------------------------------===//
|
16 | 16 |
|
17 | 17 | #include "TaskPrivate.h"
|
18 | 18 |
|
| 19 | +// Thread Sanitizer is not supported on Windows. |
19 | 20 | #if defined(_WIN32)
|
20 |
| -#define NOMINMAX |
21 |
| -#include <windows.h> |
| 21 | +void swift::_swift_tsan_acquire(void *addr) {} |
| 22 | +void swift::_swift_tsan_release(void *addr) {} |
22 | 23 | #else
|
23 | 24 | #include <dlfcn.h>
|
24 |
| -#endif |
25 | 25 |
|
26 | 26 | namespace {
|
27 | 27 | using TSanFunc = void(void *);
|
28 | 28 | TSanFunc *tsan_acquire, *tsan_release;
|
29 |
| - |
30 |
| -TSanFunc *loadSymbol(const char *name) { |
31 |
| -#if defined(_WIN32) |
32 |
| - return (TSanFunc *)GetProcAddress(GetModuleHandle(NULL), name); |
33 |
| -#else |
34 |
| - return (TSanFunc *)dlsym(RTLD_DEFAULT, name); |
35 |
| -#endif |
36 |
| -} |
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 |
| -} |
43 | 29 | } // anonymous namespace
|
44 | 30 |
|
45 | 31 | void swift::_swift_tsan_acquire(void *addr) {
|
46 |
| - swift_once(&initOnceToken, initializeThreadSanitizer, nullptr); |
47 | 32 | if (tsan_acquire) {
|
48 | 33 | tsan_acquire(addr);
|
49 | 34 | }
|
50 | 35 | }
|
51 | 36 |
|
52 | 37 | void swift::_swift_tsan_release(void *addr) {
|
53 |
| - swift_once(&initOnceToken, initializeThreadSanitizer, nullptr); |
54 | 38 | if (tsan_release) {
|
55 | 39 | tsan_release(addr);
|
56 | 40 | }
|
57 | 41 | }
|
58 | 42 |
|
59 | 43 | 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; |
| 44 | +void __tsan_on_initialize() { |
| 45 | + tsan_acquire = (TSanFunc *)dlsym(RTLD_DEFAULT, "__tsan_acquire"); |
| 46 | + tsan_release = (TSanFunc *)dlsym(RTLD_DEFAULT, "__tsan_release"); |
63 | 47 | }
|
| 48 | +#endif |
0 commit comments