forked from OSchip/llvm-project
tsan: make cur_thread_init return cur_thread
Whenever we call cur_thread_init, we call cur_thread on the next line. So make cur_thread_init return the current thread directly. Makes code a bit shorter, does not affect codegen. Reviewed By: vitalybuka, melver Differential Revision: https://reviews.llvm.org/D110384
This commit is contained in:
parent
f4f9ad0f5d
commit
a0ed71ff29
|
@ -32,16 +32,14 @@ LibIgnore *libignore();
|
||||||
|
|
||||||
#if !SANITIZER_GO
|
#if !SANITIZER_GO
|
||||||
inline bool in_symbolizer() {
|
inline bool in_symbolizer() {
|
||||||
cur_thread_init();
|
return UNLIKELY(cur_thread_init()->in_symbolizer);
|
||||||
return UNLIKELY(cur_thread()->in_symbolizer);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace __tsan
|
} // namespace __tsan
|
||||||
|
|
||||||
#define SCOPED_INTERCEPTOR_RAW(func, ...) \
|
#define SCOPED_INTERCEPTOR_RAW(func, ...) \
|
||||||
cur_thread_init(); \
|
ThreadState *thr = cur_thread_init(); \
|
||||||
ThreadState *thr = cur_thread(); \
|
|
||||||
const uptr caller_pc = GET_CALLER_PC(); \
|
const uptr caller_pc = GET_CALLER_PC(); \
|
||||||
ScopedInterceptor si(thr, #func, caller_pc); \
|
ScopedInterceptor si(thr, #func, caller_pc); \
|
||||||
const uptr pc = GET_CURRENT_PC(); \
|
const uptr pc = GET_CURRENT_PC(); \
|
||||||
|
|
|
@ -153,7 +153,7 @@ const int SIG_SETMASK = 2;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED \
|
#define COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED \
|
||||||
(cur_thread_init(), !cur_thread()->is_inited)
|
(!cur_thread_init()->is_inited)
|
||||||
|
|
||||||
namespace __tsan {
|
namespace __tsan {
|
||||||
struct SignalDesc {
|
struct SignalDesc {
|
||||||
|
@ -531,10 +531,7 @@ static void LongJmp(ThreadState *thr, uptr *env) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: put everything below into a common extern "C" block?
|
// FIXME: put everything below into a common extern "C" block?
|
||||||
extern "C" void __tsan_setjmp(uptr sp) {
|
extern "C" void __tsan_setjmp(uptr sp) { SetJmp(cur_thread_init(), sp); }
|
||||||
cur_thread_init();
|
|
||||||
SetJmp(cur_thread(), sp);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if SANITIZER_MAC
|
#if SANITIZER_MAC
|
||||||
TSAN_INTERCEPTOR(int, setjmp, void *env);
|
TSAN_INTERCEPTOR(int, setjmp, void *env);
|
||||||
|
@ -973,8 +970,7 @@ extern "C" void *__tsan_thread_start_func(void *arg) {
|
||||||
void* (*callback)(void *arg) = p->callback;
|
void* (*callback)(void *arg) = p->callback;
|
||||||
void *param = p->param;
|
void *param = p->param;
|
||||||
{
|
{
|
||||||
cur_thread_init();
|
ThreadState *thr = cur_thread_init();
|
||||||
ThreadState *thr = cur_thread();
|
|
||||||
// Thread-local state is not initialized yet.
|
// Thread-local state is not initialized yet.
|
||||||
ScopedIgnoreInterceptors ignore;
|
ScopedIgnoreInterceptors ignore;
|
||||||
#if !SANITIZER_MAC && !SANITIZER_NETBSD && !SANITIZER_FREEBSD
|
#if !SANITIZER_MAC && !SANITIZER_NETBSD && !SANITIZER_FREEBSD
|
||||||
|
@ -2061,8 +2057,7 @@ static bool is_sync_signal(ThreadSignalContext *sctx, int sig) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void sighandler(int sig, __sanitizer_siginfo *info, void *ctx) {
|
void sighandler(int sig, __sanitizer_siginfo *info, void *ctx) {
|
||||||
cur_thread_init();
|
ThreadState *thr = cur_thread_init();
|
||||||
ThreadState *thr = cur_thread();
|
|
||||||
ThreadSignalContext *sctx = SigCtx(thr);
|
ThreadSignalContext *sctx = SigCtx(thr);
|
||||||
if (sig < 0 || sig >= kSigCount) {
|
if (sig < 0 || sig >= kSigCount) {
|
||||||
VPrintf(1, "ThreadSanitizer: ignoring signal %d\n", sig);
|
VPrintf(1, "ThreadSanitizer: ignoring signal %d\n", sig);
|
||||||
|
|
|
@ -20,10 +20,7 @@
|
||||||
|
|
||||||
using namespace __tsan;
|
using namespace __tsan;
|
||||||
|
|
||||||
void __tsan_init() {
|
void __tsan_init() { Initialize(cur_thread_init()); }
|
||||||
cur_thread_init();
|
|
||||||
Initialize(cur_thread());
|
|
||||||
}
|
|
||||||
|
|
||||||
void __tsan_flush_memory() {
|
void __tsan_flush_memory() {
|
||||||
FlushShadowMemory();
|
FlushShadowMemory();
|
||||||
|
|
|
@ -196,8 +196,7 @@ static void *BackgroundThread(void *arg) {
|
||||||
// We don't use ScopedIgnoreInterceptors, because we want ignores to be
|
// We don't use ScopedIgnoreInterceptors, because we want ignores to be
|
||||||
// enabled even when the thread function exits (e.g. during pthread thread
|
// enabled even when the thread function exits (e.g. during pthread thread
|
||||||
// shutdown code).
|
// shutdown code).
|
||||||
cur_thread_init();
|
cur_thread_init()->ignore_interceptors++;
|
||||||
cur_thread()->ignore_interceptors++;
|
|
||||||
const u64 kMs2Ns = 1000 * 1000;
|
const u64 kMs2Ns = 1000 * 1000;
|
||||||
const u64 start = NanoTime();
|
const u64 start = NanoTime();
|
||||||
|
|
||||||
|
|
|
@ -230,17 +230,18 @@ struct ThreadState {
|
||||||
ThreadState *cur_thread();
|
ThreadState *cur_thread();
|
||||||
void set_cur_thread(ThreadState *thr);
|
void set_cur_thread(ThreadState *thr);
|
||||||
void cur_thread_finalize();
|
void cur_thread_finalize();
|
||||||
inline void cur_thread_init() { }
|
inline ThreadState *cur_thread_init() { return cur_thread(); }
|
||||||
# else
|
# else
|
||||||
__attribute__((tls_model("initial-exec")))
|
__attribute__((tls_model("initial-exec")))
|
||||||
extern THREADLOCAL char cur_thread_placeholder[];
|
extern THREADLOCAL char cur_thread_placeholder[];
|
||||||
inline ThreadState *cur_thread() {
|
inline ThreadState *cur_thread() {
|
||||||
return reinterpret_cast<ThreadState *>(cur_thread_placeholder)->current;
|
return reinterpret_cast<ThreadState *>(cur_thread_placeholder)->current;
|
||||||
}
|
}
|
||||||
inline void cur_thread_init() {
|
inline ThreadState *cur_thread_init() {
|
||||||
ThreadState *thr = reinterpret_cast<ThreadState *>(cur_thread_placeholder);
|
ThreadState *thr = reinterpret_cast<ThreadState *>(cur_thread_placeholder);
|
||||||
if (UNLIKELY(!thr->current))
|
if (UNLIKELY(!thr->current))
|
||||||
thr->current = thr;
|
thr->current = thr;
|
||||||
|
return thr->current;
|
||||||
}
|
}
|
||||||
inline void set_cur_thread(ThreadState *thr) {
|
inline void set_cur_thread(ThreadState *thr) {
|
||||||
reinterpret_cast<ThreadState *>(cur_thread_placeholder)->current = thr;
|
reinterpret_cast<ThreadState *>(cur_thread_placeholder)->current = thr;
|
||||||
|
|
Loading…
Reference in New Issue