diff options
| author | Dean Michael Berris <dberris@google.com> | 2017-10-03 06:11:20 +0000 |
|---|---|---|
| committer | Dean Michael Berris <dberris@google.com> | 2017-10-03 06:11:20 +0000 |
| commit | 4204464c76845b1b9334ab1758e3a72120af84c3 (patch) | |
| tree | 5a4faa5fda89c8a52ddf7ef9c8ae232815c6bd18 /compiler-rt/lib/xray | |
| parent | 1dbf45dc2751cadd7c3d0df6b3e19589fc4753f7 (diff) | |
| download | bcm5719-llvm-4204464c76845b1b9334ab1758e3a72120af84c3.tar.gz bcm5719-llvm-4204464c76845b1b9334ab1758e3a72120af84c3.zip | |
fixup: use UNUSED, restore alignment for cache-line friendliness, and report on errors found when pthread_create_key fails
llvm-svn: 314765
Diffstat (limited to 'compiler-rt/lib/xray')
| -rw-r--r-- | compiler-rt/lib/xray/xray_fdr_logging_impl.h | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/compiler-rt/lib/xray/xray_fdr_logging_impl.h b/compiler-rt/lib/xray/xray_fdr_logging_impl.h index 28e70f89103..aec205e8a34 100644 --- a/compiler-rt/lib/xray/xray_fdr_logging_impl.h +++ b/compiler-rt/lib/xray/xray_fdr_logging_impl.h @@ -93,8 +93,10 @@ static void writeEOBMetadata(); static void writeTSCWrapMetadata(uint64_t TSC); // Group together thread-local-data in a struct, then hide it behind a function -// call so that it can be initialized on first use instead of as a global. -struct ThreadLocalData { +// call so that it can be initialized on first use instead of as a global. We +// force the alignment to 64-bytes for x86 cache line alignment, as this +// structure is used in the hot path of implementation. +struct ALIGNED(64) ThreadLocalData { BufferQueue::Buffer Buffer; char *RecordPtr = nullptr; // The number of FunctionEntry records immediately preceding RecordPtr. @@ -174,12 +176,13 @@ static ThreadLocalData &getThreadLocalData() { // We need aligned, uninitialized storage for the TLS object which is // trivially destructible. We're going to use this as raw storage and // placement-new the ThreadLocalData object into it later. - thread_local std::aligned_union<1, ThreadLocalData>::type TLSBuffer; + thread_local std::aligned_storage<sizeof(ThreadLocalData), + alignof(ThreadLocalData)>::type TLSBuffer; // Ensure that we only actually ever do the pthread initialization once. - thread_local bool unused = [] { + thread_local bool UNUSED Unused = [] { new (&TLSBuffer) ThreadLocalData(); - pthread_key_create(&key, +[](void *) { + auto result = pthread_key_create(&key, +[](void *) { auto &TLD = *reinterpret_cast<ThreadLocalData *>(&TLSBuffer); auto &RecordPtr = TLD.RecordPtr; auto &Buffers = TLD.LocalBQ; @@ -203,10 +206,14 @@ static ThreadLocalData &getThreadLocalData() { return; } }); + if (result != 0) { + Report("Failed to allocate thread-local data through pthread; error=%d", + result); + return false; + } pthread_setspecific(key, &TLSBuffer); return true; }(); - (void)unused; return *reinterpret_cast<ThreadLocalData *>(&TLSBuffer); } |

