Release reference to mem_object after command submission.

Change-Id: I1d3899ee3320869dd245dc1af22bd9b0dbfce9cf
Signed-off-by: Mrozek, Michal <michal.mrozek@intel.com>
This commit is contained in:
Mrozek, Michal
2019-07-05 10:02:27 +02:00
committed by sys_ocldev
parent 5a0be86b04
commit 1022ad4aac
3 changed files with 24 additions and 5 deletions

View File

@ -42,12 +42,9 @@ CommandMapUnmap::CommandMapUnmap(MapOperationType op, MemObj &memObj, MemObjSize
memObj.incRefInternal();
}
CommandMapUnmap::~CommandMapUnmap() {
memObj.decRefInternal();
}
CompletionStamp &CommandMapUnmap::submit(uint32_t taskLevel, bool terminated) {
if (terminated) {
memObj.decRefInternal();
return completionStamp;
}
@ -90,6 +87,8 @@ CompletionStamp &CommandMapUnmap::submit(uint32_t taskLevel, bool terminated) {
}
}
memObj.decRefInternal();
return completionStamp;
}

View File

@ -52,7 +52,7 @@ class CommandMapUnmap : public Command {
public:
CommandMapUnmap(MapOperationType op, MemObj &memObj, MemObjSizeArray &copySize, MemObjOffsetArray &copyOffset, bool readOnly,
CommandStreamReceiver &csr, CommandQueue &cmdQ);
~CommandMapUnmap() override;
~CommandMapUnmap() override = default;
CompletionStamp &submit(uint32_t taskLevel, bool terminated) override;
private:

View File

@ -738,6 +738,26 @@ TEST_F(InternalsEventTest, processBlockedCommandsUnMapOperation) {
delete pCmdQ;
}
TEST_F(InternalsEventTest, givenBlockedMapCommandWhenSubmitIsCalledItReleasesMemObjectReference) {
MockEvent<Event> event(nullptr, CL_COMMAND_NDRANGE_KERNEL, 0, 0);
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};
auto pCmdQ = std::make_unique<CommandQueue>(mockContext, pDevice, props);
auto &csr = pCmdQ->getCommandStreamReceiver();
auto buffer = new UnalignedBuffer;
auto currentBufferRefInternal = buffer->getRefInternalCount();
MemObjSizeArray size = {{1, 1, 1}};
MemObjOffsetArray offset = {{0, 0, 0}};
event.setCommand(std::unique_ptr<Command>(new CommandMapUnmap(UNMAP, *buffer, size, offset, false, csr, *pCmdQ)));
EXPECT_EQ(currentBufferRefInternal + 1, buffer->getRefInternalCount());
event.submitCommand(false);
EXPECT_EQ(currentBufferRefInternal, buffer->getRefInternalCount());
buffer->decRefInternal();
}
TEST_F(InternalsEventTest, processBlockedCommandsUnMapOperationNonZeroCopyBuffer) {
MockEvent<Event> event(nullptr, CL_COMMAND_NDRANGE_KERNEL, 0, 0);
const cl_queue_properties props[3] = {CL_QUEUE_PROPERTIES, 0, 0};