This commit is contained in:
2026-03-17 18:13:23 +03:00
parent 8ccc05ee78
commit ac877f1024
3 changed files with 48 additions and 28 deletions

View File

@@ -25,7 +25,6 @@
#include <atomic>
#include <chrono>
#include <climits>
#include <memory>
#include <thread>
#include <vector>
@@ -35,7 +34,6 @@ namespace {
constexpr int THREAD_COUNT = 10;
constexpr int ITERATIONS_PER_THREAD = 1000;
constexpr int WAIT_THREAD_TIME_MS = 1000;
} // anonymous namespace
@@ -229,7 +227,7 @@ TEST(PIProtectedVariable_ThreadSafety, MixedReadWriteOperations) {
// Reader threads
vector<thread> readers;
for (int i = 0; i < THREAD_COUNT; ++i) {
readers.emplace_back([&pv, &readCount, &invalidReads, &start, NUM_WRITER_ITERATIONS]() {
readers.emplace_back([&pv, &readCount, &invalidReads, &start]() {
while (!start.load()) {
this_thread::yield();
}
@@ -468,8 +466,6 @@ TEST(PIProtectedVariable_Move, MoveConstructorTransfersLockOwnership) {
PIProtectedVariable<int> pv;
pv.set(42);
atomic<int> unlockCount(0);
// We can't directly test unlock count without modifying the class,
// but we can test the behavior: after move, only the target should unlock
@@ -503,8 +499,6 @@ TEST(PIProtectedVariable_Move, SourceDoesNotUnlockAfterMove) {
PIProtectedVariable<int> pv;
pv.set(42);
atomic<bool> deadlockOccurred(false);
// If source unlocked after move, we would get a double-unlock error
// or undefined behavior. This test verifies that moving works correctly.
@@ -569,15 +563,11 @@ TEST(PIProtectedVariable_Move, MoveWithRVODisabled) {
// This test should be compiled with -fno-elide-constructors
// to ensure move constructor is actually called
PIProtectedVariable<int> pv;
pv.set(42);
PIProtectedVariable<int> pv(42);
auto createAndMove = [&pv]() -> decltype(pv.getRef()) {
auto ptr = pv.getRef();
return std::move(ptr);
};
auto ptr = createAndMove();
auto ptr_src = pv.getRef();
*ptr_src = 99;
auto ptr = std::move(ptr_src);
*ptr = 100;
EXPECT_EQ(pv.get(), 100);