Commit f0bada9d authored by Yu Zhao's avatar Yu Zhao Committed by Facebook GitHub Bot

Fix mutex lock issue at the end of tsan test

Summary:
During tsan test, sometimes annotationGuard() is called after kAnnotationMutexes is already destroyed which throws exception.
This change fix the issue by uses Indestructible for kAnnotationMutexes, so that it is not destroyed.

Reviewed By: yfeldblum

Differential Revision: D25443571

fbshipit-source-id: 69411a7edc4f96ba8c7d08bd29f87ab7b2ff78ae
parent 66d50da2
......@@ -15,6 +15,7 @@
*/
#include <folly/SharedMutex.h>
#include <folly/Indestructible.h>
namespace folly {
// Explicitly instantiate SharedMutex here:
......@@ -28,9 +29,10 @@ std::unique_lock<std::mutex> annotationGuard(void* ptr) {
// the address. If the array is of prime size things will work out okay
// without a complicated hash function.
static constexpr std::size_t kNumAnnotationMutexes = 251;
static std::array<std::mutex, kNumAnnotationMutexes> kAnnotationMutexes{};
static Indestructible<std::array<std::mutex, kNumAnnotationMutexes>>
kAnnotationMutexes;
auto index = reinterpret_cast<uintptr_t>(ptr) % kNumAnnotationMutexes;
return std::unique_lock<std::mutex>(kAnnotationMutexes[index]);
return std::unique_lock<std::mutex>((*kAnnotationMutexes)[index]);
} else {
return std::unique_lock<std::mutex>();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment