[Threading][TSan] Fix TSan errors from lazy init on Linux.

Move the TSan functionality from Concurrency into Threading.  Use it
in the Linux `ulock` implementation so that TSan knows about `ulock`
and will tolerate the newer `swift_once` implementation that uses it.

rdar://110665213
This commit is contained in:
Alastair Houghton
2023-06-16 13:30:36 +01:00
parent 8caf9997c9
commit 41f46ec085
10 changed files with 231 additions and 72 deletions

View File

@@ -18,6 +18,7 @@
#include "swift/Threading/Impl.h"
#include "swift/Threading/Errors.h"
#include "swift/Threading/TSan.h"
namespace {
@@ -61,7 +62,7 @@ void swift::threading_impl::once_slow(once_t &predicate, void (*fn)(void *),
#endif
if (predicate.flag.load(std::memory_order_acquire) == 0) {
fn(context);
predicate.flag.store(-1, std::memory_order_release);
predicate.flag.store(tsan::enabled() ? 1 : -1, std::memory_order_release);
}
#if defined(__LP64__) || defined(_LP64)
linux::ulock_unlock(&predicate.lock);