// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifdef UNSAFE_BUFFERS_BUILD // TODO(crbug.com/40285824): Remove this and convert code to safer constructs. #pragma allow_unsafe_buffers #endif #include "base/memory/raw_ptr.h" #include "base/threading/platform_thread.h" #include "components/viz/service/debugger/rwlock.h" #include "testing/gtest/include/gtest/gtest.h" namespace { // Shared global variables int writer_count = …; static const unsigned kNumCounts = …; class RWLockTest : public testing::Test { … }; rwlock::RWLock RWLockTest::test_rwlock; // The writer thread reads through the entire vector at a certain // state left by the readers, sums up all the existing integer // values, stores it, and resets the vector to provide a blank // slate for the reader threads to continue working on. class WriterThread : public base::PlatformThread::Delegate { … }; // Each reader thread has a corresponding slot within the shared // vector. Within each slot, each reader thread increments the slot's // integer value by 1 for k number (kNumCounts) of iterations. // Within each iteration, there is a small time buffer/delay (kNumTimeDelay) // to allow the writer thread to squeeze and take the lock. class ReaderThread : public base::PlatformThread::Delegate { … }; TEST_F(RWLockTest, ReadWrite) { … } } // namespace