Skip to content

Commit 5187382

Browse files
author
Julian Lettner
committed
Add support for calling TSan's acquire()/release()
1 parent e023695 commit 5187382

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
6565
TaskGroup.swift
6666
TaskLocal.cpp
6767
TaskLocal.swift
68+
ThreadSanitizer.cpp
6869
Mutex.cpp
6970
${swift_concurrency_objc_sources}
7071

stdlib/public/Concurrency/TaskPrivate.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ void donateThreadToGlobalExecutorUntil(bool (*condition)(void*),
5656
void *context);
5757
#endif
5858

59+
/// release() establishes a happens-before relation with a preceding acquire()
60+
/// on the same address.
61+
void _swift_tsan_acquire(void *addr);
62+
void _swift_tsan_release(void *addr);
63+
5964
// ==== ------------------------------------------------------------------------
6065
// TODO: this was moved from Task.cpp to share it with TaskGroup.cpp, where else better place to put it?
6166

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===--- ThreadSanitizer.cpp - Thread Sanitizer support -------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// Thread Sanitizer support for the Swift Task runtime
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#include "TaskPrivate.h"
18+
19+
#include <dlfcn.h>
20+
21+
using TSanFunc = void(void *);
22+
23+
void swift::_swift_tsan_acquire(void *addr) {
24+
static auto ptr = (TSanFunc *)dlsym(RTLD_DEFAULT, "__tsan_acquire");
25+
if (ptr) {
26+
ptr(addr);
27+
}
28+
}
29+
30+
void swift::_swift_tsan_release(void *addr) {
31+
static auto ptr = (TSanFunc *)dlsym(RTLD_DEFAULT, "__tsan_release");
32+
if (ptr) {
33+
ptr(addr);
34+
}
35+
}

0 commit comments

Comments
 (0)