Skip to content

Commit 7eceb30

Browse files
Do no increment ref counts when passing OsContext to residency.
- not needed anymore, memory manager manages the ilfecycle of OsContext Change-Id: Ibcb32954522dd862187cf97d62d2e0b1b10e50e5
1 parent b74280b commit 7eceb30

File tree

3 files changed

+12
-31
lines changed

3 files changed

+12
-31
lines changed

runtime/memory_manager/residency.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,7 @@ using namespace OCLRT;
2828

2929
void ResidencyData::addOsContext(OsContext *osContext) {
3030
if (!this->osContext) {
31-
osContext->incRefInternal();
3231
this->osContext = osContext;
3332
}
3433
DEBUG_BREAK_IF(this->osContext != osContext);
3534
}
36-
37-
ResidencyData::~ResidencyData() {
38-
if (osContext) {
39-
osContext->decRefInternal();
40-
}
41-
}

runtime/memory_manager/residency.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class OsContext;
2828
struct ResidencyData {
2929
ResidencyData() = default;
3030
void addOsContext(OsContext *osContext);
31-
~ResidencyData();
31+
~ResidencyData() = default;
3232
bool resident = false;
3333
uint64_t lastFence = 0;
3434
OsContext *osContext = nullptr;

unit_tests/memory_manager/memory_manager_tests.cpp

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,33 +1802,21 @@ TEST(GraphicsAllocation, givenSharedHandleBasedConstructorWhenGraphicsAllocation
18021802
EXPECT_EQ(expectedGpuAddress, graphicsAllocation.getGpuAddress());
18031803
}
18041804

1805-
TEST(ResidencyDataTest, givenResidencyDataWithOsContextWhenDestructorIsCalledThenDecrementRefCount) {
1806-
OsContext *osContext = new OsContext(nullptr);
1807-
osContext->incRefInternal();
1808-
EXPECT_EQ(1, osContext->getRefInternalCount());
1809-
{
1810-
ResidencyData residencyData;
1811-
residencyData.addOsContext(osContext);
1812-
EXPECT_EQ(2, osContext->getRefInternalCount());
1813-
}
1814-
EXPECT_EQ(1, osContext->getRefInternalCount());
1815-
osContext->decRefInternal();
1816-
}
1817-
1818-
TEST(ResidencyDataTest, givenResidencyDataWhenAddTheSameOsContextTwiceThenIncrementRefCounterOnlyOnce) {
1819-
OsContext *osContext = new OsContext(nullptr);
1820-
ResidencyData residencyData;
1821-
EXPECT_EQ(0, osContext->getRefInternalCount());
1822-
residencyData.addOsContext(osContext);
1823-
EXPECT_EQ(1, osContext->getRefInternalCount());
1824-
residencyData.addOsContext(osContext);
1825-
EXPECT_EQ(1, osContext->getRefInternalCount());
1826-
}
1827-
18281805
TEST(ResidencyDataTest, givenOsContextWhenItIsRegisteredToMemoryManagerThenRefCountIncreases) {
18291806
auto osContext = new OsContext(nullptr);
18301807
OsAgnosticMemoryManager memoryManager;
18311808
memoryManager.registerOsContext(osContext);
18321809
EXPECT_EQ(1u, memoryManager.getOsContextCount());
18331810
EXPECT_EQ(1, osContext->getRefInternalCount());
18341811
}
1812+
1813+
TEST(ResidencyDataTest, givenOsContextWhenItIsAddedToResidencyThenItCantBeOverwritten) {
1814+
ResidencyData residency;
1815+
OsContext osContext(nullptr);
1816+
OsContext osContext2(nullptr);
1817+
EXPECT_EQ(nullptr, residency.osContext);
1818+
residency.addOsContext(&osContext);
1819+
EXPECT_EQ(&osContext, residency.osContext);
1820+
residency.addOsContext(&osContext2);
1821+
EXPECT_EQ(&osContext, residency.osContext);
1822+
}

0 commit comments

Comments
 (0)