From 95ddf85f8075d5645a754bac5742b72ec9c81f2a Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 13 Nov 2017 10:04:29 -0800 Subject: [PATCH] Changes imported from Abseil "staging" branch: - 5677afe8f626bb9db6d8bf9f25ba3d835ffa12d6 Internal TSAN bookkeeping change. by Greg Falcon - c7492bad6fe6c8f106d3fcb1f8a939ea73b1a962 MSVC fix. by Alex Strelnikov GitOrigin-RevId: 5677afe8f626bb9db6d8bf9f25ba3d835ffa12d6 Change-Id: I1b8497508c8005a094824b4ccf9b220812b81bdb --- absl/algorithm/container.h | 26 +++++++++++++------------- absl/base/internal/spinlock.cc | 4 ++-- absl/base/internal/spinlock.h | 6 +++--- absl/synchronization/mutex.cc | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/absl/algorithm/container.h b/absl/algorithm/container.h index 740e2071a..839a6adc0 100644 --- a/absl/algorithm/container.h +++ b/absl/algorithm/container.h @@ -69,6 +69,12 @@ using std::end; template using ContainerIter = decltype(begin(std::declval())); +// An MSVC bug involving template parameter substitution requires us to use +// decltype() here instead of just std::pair. +template +using ContainerIterPairType = + decltype(std::make_pair(ContainerIter(), ContainerIter())); + template using ContainerDifferenceType = decltype(std::distance(std::declval>(), @@ -311,8 +317,7 @@ container_algorithm_internal::ContainerDifferenceType c_count_if( // Container-based version of the `std::mismatchf()` function to // return the first element where two ordered containers differ. template -std::pair, - container_algorithm_internal::ContainerIter> +container_algorithm_internal::ContainerIterPairType c_mismatch(C1& c1, C2& c2) { return std::mismatch(container_algorithm_internal::c_begin(c1), container_algorithm_internal::c_end(c1), @@ -322,8 +327,7 @@ c_mismatch(C1& c1, C2& c2) { // Overload of c_mismatch() for using a predicate evaluation other than `==` as // the function's test condition. template -std::pair, - container_algorithm_internal::ContainerIter> +container_algorithm_internal::ContainerIterPairType c_mismatch(C1& c1, C2& c2, BinaryPredicate&& pred) { return std::mismatch(container_algorithm_internal::c_begin(c1), container_algorithm_internal::c_end(c1), @@ -869,7 +873,7 @@ void c_stable_sort(C& c, Compare&& comp) { // c_is_sorted() // // Container-based version of the `std::is_sorted()` function -// to evaluate whether the given containter is sorted in ascending order. +// to evaluate whether the given container is sorted in ascending order. template bool c_is_sorted(const C& c) { return std::is_sorted(container_algorithm_internal::c_begin(c), @@ -1042,8 +1046,7 @@ container_algorithm_internal::ContainerIter c_upper_bound( // to return an iterator pair pointing to the first and last elements in a // sorted container which compare equal to `value`. template -std::pair, - container_algorithm_internal::ContainerIter> +container_algorithm_internal::ContainerIterPairType c_equal_range(Sequence& sequence, T&& value) { return std::equal_range(container_algorithm_internal::c_begin(sequence), container_algorithm_internal::c_end(sequence), @@ -1053,8 +1056,7 @@ c_equal_range(Sequence& sequence, T&& value) { // Overload of c_equal_range() for performing a `comp` comparison other than // the default `operator<`. template -std::pair, - container_algorithm_internal::ContainerIter> +container_algorithm_internal::ContainerIterPairType c_equal_range(Sequence& sequence, T&& value, Compare&& comp) { return std::equal_range(container_algorithm_internal::c_begin(sequence), container_algorithm_internal::c_end(sequence), @@ -1437,8 +1439,7 @@ container_algorithm_internal::ContainerIter c_max_element( // smallest and largest values, respectively, using `operator<` to make the // comparisons. template -std::pair, - container_algorithm_internal::ContainerIter> +container_algorithm_internal::ContainerIterPairType c_minmax_element(C& c) { return std::minmax_element(container_algorithm_internal::c_begin(c), container_algorithm_internal::c_end(c)); @@ -1447,8 +1448,7 @@ c_minmax_element(C& c) { // Overload of c_minmax_element() for performing `comp` comparisons other than // `operator<`. template -std::pair, - container_algorithm_internal::ContainerIter> +container_algorithm_internal::ContainerIterPairType c_minmax_element(C& c, Compare&& comp) { return std::minmax_element(container_algorithm_internal::c_begin(c), container_algorithm_internal::c_end(c), diff --git a/absl/base/internal/spinlock.cc b/absl/base/internal/spinlock.cc index 517668dcc..3ac1f4dc9 100644 --- a/absl/base/internal/spinlock.cc +++ b/absl/base/internal/spinlock.cc @@ -91,12 +91,12 @@ static inline bool IsCooperative( // Uncommon constructors. SpinLock::SpinLock(base_internal::SchedulingMode mode) : lockword_(IsCooperative(mode) ? kSpinLockCooperative : 0) { - ABSL_TSAN_MUTEX_CREATE(this, 0); + ABSL_TSAN_MUTEX_CREATE(this, __tsan_mutex_not_static); } SpinLock::SpinLock(base_internal::LinkerInitialized, base_internal::SchedulingMode mode) { - ABSL_TSAN_MUTEX_CREATE(this, __tsan_mutex_linker_init); + ABSL_TSAN_MUTEX_CREATE(this, 0); if (IsCooperative(mode)) { InitLinkerInitializedAndCooperative(); } diff --git a/absl/base/internal/spinlock.h b/absl/base/internal/spinlock.h index 1f50d7459..f486f68a0 100644 --- a/absl/base/internal/spinlock.h +++ b/absl/base/internal/spinlock.h @@ -50,7 +50,7 @@ namespace base_internal { class LOCKABLE SpinLock { public: SpinLock() : lockword_(kSpinLockCooperative) { - ABSL_TSAN_MUTEX_CREATE(this, 0); + ABSL_TSAN_MUTEX_CREATE(this, __tsan_mutex_not_static); } // Special constructor for use with static SpinLock objects. E.g., @@ -64,7 +64,7 @@ class LOCKABLE SpinLock { // initializers run. explicit SpinLock(base_internal::LinkerInitialized) { // Does nothing; lockword_ is already initialized - ABSL_TSAN_MUTEX_CREATE(this, __tsan_mutex_linker_init); + ABSL_TSAN_MUTEX_CREATE(this, 0); } // Constructors that allow non-cooperative spinlocks to be created for use @@ -73,7 +73,7 @@ class LOCKABLE SpinLock { SpinLock(base_internal::LinkerInitialized, base_internal::SchedulingMode mode); - ~SpinLock() { ABSL_TSAN_MUTEX_DESTROY(this, 0); } + ~SpinLock() { ABSL_TSAN_MUTEX_DESTROY(this, __tsan_mutex_not_static); } // Acquire this SpinLock. inline void Lock() EXCLUSIVE_LOCK_FUNCTION() { diff --git a/absl/synchronization/mutex.cc b/absl/synchronization/mutex.cc index cb0a3a10a..32d9e3c2f 100644 --- a/absl/synchronization/mutex.cc +++ b/absl/synchronization/mutex.cc @@ -675,7 +675,7 @@ static unsigned TsanFlags(Mutex::MuHow how) { #endif Mutex::Mutex() : mu_(0) { - ABSL_TSAN_MUTEX_CREATE(this, 0); + ABSL_TSAN_MUTEX_CREATE(this, __tsan_mutex_not_static); } static bool DebugOnlyIsExiting() { @@ -690,7 +690,7 @@ Mutex::~Mutex() { if (kDebugMode) { this->ForgetDeadlockInfo(); } - ABSL_TSAN_MUTEX_DESTROY(this, 0); + ABSL_TSAN_MUTEX_DESTROY(this, __tsan_mutex_not_static); } void Mutex::EnableDebugLog(const char *name) {