aboutsummaryrefslogtreecommitdiff
path: root/third_party/abseil-cpp/absl/base/spinlock_test_common.cc
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-04-14 03:07:06 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-04-14 03:07:06 +0000
commit39dbb21d63fcd4848f54cf7dfc7188f7216c36f4 (patch)
tree2ce94d7f0804ccb77d1fa9b2a1bca00eecdff1e2 /third_party/abseil-cpp/absl/base/spinlock_test_common.cc
parentf60eaea2240ba9e1c508e8e0c91d39ee9fc47be5 (diff)
parent6c9587948173932b64d97c288a947e43d2a2ac14 (diff)
downloadwebrtc-39dbb21d63fcd4848f54cf7dfc7188f7216c36f4.tar.gz
Change-Id: I2cdc23e9d294e3701ac746469aea1ce793eb9ce4
Diffstat (limited to 'third_party/abseil-cpp/absl/base/spinlock_test_common.cc')
-rw-r--r--third_party/abseil-cpp/absl/base/spinlock_test_common.cc21
1 files changed, 11 insertions, 10 deletions
diff --git a/third_party/abseil-cpp/absl/base/spinlock_test_common.cc b/third_party/abseil-cpp/absl/base/spinlock_test_common.cc
index 08f61ba86a..2b572c5b3f 100644
--- a/third_party/abseil-cpp/absl/base/spinlock_test_common.cc
+++ b/third_party/abseil-cpp/absl/base/spinlock_test_common.cc
@@ -20,10 +20,12 @@
#include <limits>
#include <random>
#include <thread> // NOLINT(build/c++11)
+#include <type_traits>
#include <vector>
#include "gtest/gtest.h"
#include "absl/base/attributes.h"
+#include "absl/base/config.h"
#include "absl/base/internal/low_level_scheduling.h"
#include "absl/base/internal/scheduling_mode.h"
#include "absl/base/internal/spinlock.h"
@@ -56,12 +58,10 @@ namespace {
static constexpr int kArrayLength = 10;
static uint32_t values[kArrayLength];
-static SpinLock static_spinlock(base_internal::kLinkerInitialized);
-static SpinLock static_cooperative_spinlock(
- base_internal::kLinkerInitialized,
- base_internal::SCHEDULE_COOPERATIVE_AND_KERNEL);
-static SpinLock static_noncooperative_spinlock(
- base_internal::kLinkerInitialized, base_internal::SCHEDULE_KERNEL_ONLY);
+ABSL_CONST_INIT static SpinLock static_cooperative_spinlock(
+ absl::kConstInit, base_internal::SCHEDULE_COOPERATIVE_AND_KERNEL);
+ABSL_CONST_INIT static SpinLock static_noncooperative_spinlock(
+ absl::kConstInit, base_internal::SCHEDULE_KERNEL_ONLY);
// Simple integer hash function based on the public domain lookup2 hash.
// http://burtleburtle.net/bob/c/lookup2.c
@@ -92,6 +92,7 @@ static void TestFunction(int thread_salt, SpinLock* spinlock) {
static void ThreadedTest(SpinLock* spinlock) {
std::vector<std::thread> threads;
+ threads.reserve(kNumThreads);
for (int i = 0; i < kNumThreads; ++i) {
threads.push_back(std::thread(TestFunction, i, spinlock));
}
@@ -105,6 +106,10 @@ static void ThreadedTest(SpinLock* spinlock) {
}
}
+#ifndef ABSL_HAVE_THREAD_SANITIZER
+static_assert(std::is_trivially_destructible<SpinLock>(), "");
+#endif
+
TEST(SpinLock, StackNonCooperativeDisablesScheduling) {
SpinLock spinlock(base_internal::SCHEDULE_KERNEL_ONLY);
spinlock.Lock();
@@ -191,10 +196,6 @@ TEST(SpinLock, WaitCyclesEncoding) {
EXPECT_GT(expected_max_value_decoded, before_max_value_decoded);
}
-TEST(SpinLockWithThreads, StaticSpinLock) {
- ThreadedTest(&static_spinlock);
-}
-
TEST(SpinLockWithThreads, StackSpinLock) {
SpinLock spinlock;
ThreadedTest(&spinlock);