@@ -63,11 +63,35 @@ inline bool enabled() {
63
63
return threading_impl::_swift_tsan_enabled;
64
64
}
65
65
66
- // / Indicate to TSan that an acquiring load has occurred on the current
67
- // / thread. If some other thread does a releasing store with the same
68
- // / pointer, we are indicating to TSan that all writes that happened
69
- // / before that store will be visible to the current thread after the
70
- // / `acquire()`.
66
+ // / Inform TSan about a synchronization operation.
67
+ // /
68
+ // / This is used when TSan cannot see the synchronization operation, for
69
+ // / example, if it is using a custom primitive for which TSan doesn't have
70
+ // / a built-in interceptor. This does not necessarily mean a lock or a C(++)
71
+ // / atomic operation - it could be any kind of synchronization mechanism.
72
+ // /
73
+ // / An acquire-release pair using the same address establishes an ordering
74
+ // / constraint in TSan's happens-before graph, which TSan uses to determine
75
+ // / whether two memory accesses from different threads have a well-defined
76
+ // / order.
77
+ // /
78
+ // / For instance, in
79
+ // /
80
+ // / Thread 1 Thread 2
81
+ // /
82
+ // / access to y
83
+ // / tsan::release(x)
84
+ // / lock given away
85
+ // /
86
+ // / --> sync point -->
87
+ // /
88
+ // / lock taken
89
+ // / tsan::acquire(x)
90
+ // / access to y
91
+ // /
92
+ // / the access to y from Thread 2 is safe relative to the preceding access to
93
+ // / y on Thread 1 because it is preceded by an acquire of x that was itself
94
+ // / preceded by a release of x.
71
95
template <typename T>
72
96
T *acquire (T *ptr) {
73
97
if (threading_impl::_swift_tsan_acquire) {
@@ -76,10 +100,9 @@ T *acquire(T *ptr) {
76
100
return ptr;
77
101
}
78
102
79
- // / Indicate to TSan that a releasing store has occurred on the current
80
- // / thread. If some other thread does an acquiring load with the same
81
- // / pointer, we are indicating to TSan that that thread will be able to
82
- // / see all writes that happened before the `release()`.
103
+ // / Inform TSan about a synchronization operation.
104
+ // /
105
+ // / This is the counterpart to tsan::acquire.
83
106
template <typename T>
84
107
T *release (T *ptr) {
85
108
if (threading_impl::_swift_tsan_release) {
0 commit comments