From: Andrii Grynenko Date: Tue, 11 Apr 2017 06:30:46 +0000 (-0700) Subject: Fix TLRefCount::useGlobal to work with TSAN X-Git-Tag: v2017.04.17.00~39 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=1d11ad7a0af6277ca6ed2ad147ac16a2e7ac3760;p=folly.git Fix TLRefCount::useGlobal to work with TSAN Summary: TSAN has a limitation for the number of locks held concurrently - https://github.com/llvm-mirror/compiler-rt/blob/master/lib/sanitizer_common/sanitizer_deadlock_detector.h#L126, so we have to work around that. Reviewed By: yfeldblum Differential Revision: D4866477 fbshipit-source-id: 958251e97d91c1c46ef4e907de2cf189fb04f88e --- diff --git a/folly/experimental/TLRefCount.h b/folly/experimental/TLRefCount.h index a9da2d80..9e2a1da5 100644 --- a/folly/experimental/TLRefCount.h +++ b/folly/experimental/TLRefCount.h @@ -87,6 +87,17 @@ class TLRefCount { template static void useGlobal(const Container& refCountPtrs) { +#ifdef FOLLY_SANITIZE_THREAD + // TSAN has a limitation for the number of locks held concurrently, so it's + // safer to call useGlobal() serially. + if (refCountPtrs.size() > 1) { + for (auto refCountPtr : refCountPtrs) { + refCountPtr->useGlobal(); + } + return; + } +#endif + std::vector> lgs_; for (auto refCountPtr : refCountPtrs) { lgs_.emplace_back(refCountPtr->globalMutex_);