#include <cstdint>
#include <limits>
#include <random>
#include <thread>
#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"
#include "absl/base/internal/sysinfo.h"
#include "absl/base/macros.h"
#include "absl/synchronization/blocking_counter.h"
#include "absl/synchronization/notification.h"
constexpr uint32_t kNumThreads = …;
constexpr int32_t kIters = …;
namespace absl {
ABSL_NAMESPACE_BEGIN
namespace base_internal {
struct SpinLockTest { … };
namespace {
static constexpr size_t kArrayLength = …;
static uint32_t values[kArrayLength];
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);
static uint32_t Hash32(uint32_t a, uint32_t c) { … }
static void TestFunction(uint32_t thread_salt, SpinLock* spinlock) { … }
static void ThreadedTest(SpinLock* spinlock) { … }
#ifndef ABSL_HAVE_THREAD_SANITIZER
static_assert …;
#endif
TEST(SpinLock, StackNonCooperativeDisablesScheduling) { … }
TEST(SpinLock, StaticNonCooperativeDisablesScheduling) { … }
TEST(SpinLock, WaitCyclesEncoding) { … }
TEST(SpinLockWithThreads, StackSpinLock) { … }
TEST(SpinLockWithThreads, StackCooperativeSpinLock) { … }
TEST(SpinLockWithThreads, StackNonCooperativeSpinLock) { … }
TEST(SpinLockWithThreads, StaticCooperativeSpinLock) { … }
TEST(SpinLockWithThreads, StaticNonCooperativeSpinLock) { … }
TEST(SpinLockWithThreads, DoesNotDeadlock) { … }
TEST(SpinLockTest, IsCooperative) { … }
}
}
ABSL_NAMESPACE_END
}