sc_mm.cc revision 13820
12SN/A/* 21762SN/A * Copyright (c) 2015, University of Kaiserslautern 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: 82SN/A * 92SN/A * 1. Redistributions of source code must retain the above copyright notice, 102SN/A * this list of conditions and the following disclaimer. 112SN/A * 122SN/A * 2. Redistributions in binary form must reproduce the above copyright 132SN/A * notice, this list of conditions and the following disclaimer in the 142SN/A * documentation and/or other materials provided with the distribution. 152SN/A * 162SN/A * 3. Neither the name of the copyright holder nor the names of its 172SN/A * contributors may be used to endorse or promote products derived from 182SN/A * this software without specific prior written permission. 192SN/A * 202SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 212SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 222SN/A * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 232SN/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 242SN/A * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 252SN/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 262SN/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 272665Ssaidi@eecs.umich.edu * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 282665Ssaidi@eecs.umich.edu * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 292665Ssaidi@eecs.umich.edu * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 302SN/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 312SN/A * 322SN/A * Authors: 332SN/A * Robert Gernhardt 342SN/A * Matthias Jung 352520SN/A */ 362207SN/A 372207SN/A#include "systemc/tlm_bridge/sc_mm.hh" 386214Snate@binkert.org 392SN/Anamespace Gem5SystemC 402519SN/A{ 412SN/A 422SN/AMemoryManager::MemoryManager() : numberOfAllocations(0), numberOfFrees(0) {} 432SN/A 442SN/AMemoryManager::~MemoryManager() 45360SN/A{ 46360SN/A for (gp *payload: freePayloads) { 47360SN/A delete payload; 48360SN/A numberOfFrees++; 492207SN/A } 504111Sgblack@eecs.umich.edu} 514111Sgblack@eecs.umich.edu 524155Sgblack@eecs.umich.edugp * 535874Sgblack@eecs.umich.eduMemoryManager::allocate() 545874Sgblack@eecs.umich.edu{ 555335Shines@cs.fsu.edu if (freePayloads.empty()) { 56360SN/A numberOfAllocations++; 57360SN/A return new gp(this); 58360SN/A } else { 59360SN/A gp *result = freePayloads.back(); 60360SN/A freePayloads.pop_back(); 612207SN/A return result; 622207SN/A } 63360SN/A} 64360SN/A 652SN/Avoid 6612SN/AMemoryManager::free(gp *payload) 672SN/A{ 6812SN/A payload->reset(); // clears all extensions 692SN/A freePayloads.push_back(payload); 702SN/A} 71360SN/A 72360SN/A} // namespace Gem5SystemC 73360SN/A