From f54020eb8155371725ab75b0fc5c419287eca084 Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Mon, 4 Jun 2018 09:40:19 +0100 Subject: misc: Using smart pointers for memory Requests This patch is changing the underlying type for RequestPtr from Request* to shared_ptr. Having memory requests being managed by smart pointers will simplify the code; it will also prevent memory leakage and dangling pointers. Change-Id: I7749af38a11ac8eb4d53d8df1252951e0890fde3 Signed-off-by: Giacomo Travaglini Reviewed-by: Andreas Sandberg Reviewed-on: https://gem5-review.googlesource.com/10996 Reviewed-by: Nikos Nikoleris Maintainer: Nikos Nikoleris --- src/cpu/o3/fetch_impl.hh | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/cpu/o3/fetch_impl.hh') diff --git a/src/cpu/o3/fetch_impl.hh b/src/cpu/o3/fetch_impl.hh index 2e8ec67ae..2df7b84ee 100644 --- a/src/cpu/o3/fetch_impl.hh +++ b/src/cpu/o3/fetch_impl.hh @@ -388,7 +388,6 @@ DefaultFetch::processCacheCompletion(PacketPtr pkt) if (fetchStatus[tid] != IcacheWaitResponse || pkt->req != memReq[tid]) { ++fetchIcacheSquashes; - delete pkt->req; delete pkt; return; } @@ -415,7 +414,6 @@ DefaultFetch::processCacheCompletion(PacketPtr pkt) pkt->req->setAccessLatency(); cpu->ppInstAccessComplete->notify(pkt); // Reset the mem req to NULL. - delete pkt->req; delete pkt; memReq[tid] = NULL; } @@ -621,10 +619,10 @@ DefaultFetch::fetchCacheLine(Addr vaddr, ThreadID tid, Addr pc) // Setup the memReq to do a read of the first instruction's address. // Set the appropriate read size and flags as well. // Build request here. - RequestPtr mem_req = - new Request(tid, fetchBufferBlockPC, fetchBufferSize, - Request::INST_FETCH, cpu->instMasterId(), pc, - cpu->thread[tid]->contextId()); + RequestPtr mem_req = std::make_shared( + tid, fetchBufferBlockPC, fetchBufferSize, + Request::INST_FETCH, cpu->instMasterId(), pc, + cpu->thread[tid]->contextId()); mem_req->taskId(cpu->taskId()); @@ -640,7 +638,8 @@ DefaultFetch::fetchCacheLine(Addr vaddr, ThreadID tid, Addr pc) template void -DefaultFetch::finishTranslation(const Fault &fault, RequestPtr mem_req) +DefaultFetch::finishTranslation(const Fault &fault, + const RequestPtr &mem_req) { ThreadID tid = cpu->contextToThread(mem_req->contextId()); Addr fetchBufferBlockPC = mem_req->getVaddr(); @@ -655,7 +654,6 @@ DefaultFetch::finishTranslation(const Fault &fault, RequestPtr mem_req) DPRINTF(Fetch, "[tid:%i] Ignoring itlb completed after squash\n", tid); ++fetchTlbSquashes; - delete mem_req; return; } @@ -669,7 +667,6 @@ DefaultFetch::finishTranslation(const Fault &fault, RequestPtr mem_req) warn("Address %#x is outside of physical memory, stopping fetch\n", mem_req->getPaddr()); fetchStatus[tid] = NoGoodAddr; - delete mem_req; memReq[tid] = NULL; return; } @@ -717,7 +714,6 @@ DefaultFetch::finishTranslation(const Fault &fault, RequestPtr mem_req) DPRINTF(Fetch, "[tid:%i] Got back req with addr %#x but expected %#x\n", tid, mem_req->getVaddr(), memReq[tid]->getVaddr()); // Translation faulted, icache request won't be sent. - delete mem_req; memReq[tid] = NULL; // Send the fault to commit. This thread will not do anything @@ -778,7 +774,6 @@ DefaultFetch::doSquash(const TheISA::PCState &newPC, if (retryTid == tid) { assert(cacheBlocked); if (retryPkt) { - delete retryPkt->req; delete retryPkt; } retryPkt = NULL; -- cgit v1.2.3