Files
brandon schaefer ce8c4f2aa0 Release the locks after trying to check if its write is not locked
[CL 33355255 by brandon schaefer in ue5-main branch]
2024-04-30 17:38:40 -04:00

46 lines
999 B
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Catch2Includes.h"
#include "Misc/ScopeRWLock.h"
#include <AutoRTFM/AutoRTFM.h>
#include <map>
#include <vector>
TEST_CASE("ReadLock")
{
FRWLock ReadLock;
int x = 42;
auto Transaction = AutoRTFM::Transact([&]()
{
FReadScopeLock ScopeLock(ReadLock);
x = 43;
});
REQUIRE(x == 43);
// the read lock should have been released, we verify that by trying to acquire a write lock here
REQUIRE(ReadLock.TryWriteLock());
ReadLock.WriteUnlock();
}
TEST_CASE("ReadLockAbort")
{
FRWLock ReadLock;
int x = 42;
auto Transaction = AutoRTFM::Transact([&]()
{
FReadScopeLock ScopeLock(ReadLock);
x = 43;
AutoRTFM::AbortTransaction();
});
REQUIRE(
AutoRTFM::ETransactionResult::AbortedByRequest ==
Transaction);
REQUIRE(x == 42);
// the read lock should have been released, we verify that by trying to acquire a write lock here
REQUIRE(ReadLock.TryWriteLock());
ReadLock.WriteUnlock();
}