mm.h revision 12855
12SN/A 21762SN/A// ******************************************************************* 32SN/A// User-defined memory manager, which maintains a pool of transactions 42SN/A// ******************************************************************* 52SN/A 62SN/A#include "tlm.h" 72SN/A 82SN/Aclass mm: public tlm::tlm_mm_interface 92SN/A{ 102SN/A typedef tlm::tlm_generic_payload gp_t; 112SN/A 122SN/Apublic: 132SN/A mm() : free_list(0), empties(0) {} 142SN/A 152SN/A virtual ~mm() 162SN/A { 172SN/A gp_t* ptr; 182SN/A 192SN/A while (free_list) 202SN/A { 212SN/A ptr = free_list->trans; 222SN/A 232SN/A // Delete generic payload and all extensions 242SN/A sc_assert(ptr); 252SN/A delete ptr; 262SN/A 272665Ssaidi@eecs.umich.edu free_list = free_list->next; 282665Ssaidi@eecs.umich.edu } 292665Ssaidi@eecs.umich.edu 302665Ssaidi@eecs.umich.edu while (empties) 312SN/A { 322SN/A access* x = empties; 332623SN/A empties = empties->next; 342623SN/A 352SN/A // Delete free list access struct 364182Sgblack@eecs.umich.edu delete x; 371354SN/A } 381858SN/A } 391717SN/A 402683Sktlim@umich.edu gp_t* allocate(); 411354SN/A void free(gp_t* trans); 421354SN/A 432387SN/Aprivate: 442387SN/A struct access 452387SN/A { 4656SN/A gp_t* trans; 472SN/A access* next; 482SN/A access* prev; 491858SN/A }; 502SN/A 513453Sgblack@eecs.umich.edu access* free_list; 523453Sgblack@eecs.umich.edu access* empties; 533453Sgblack@eecs.umich.edu}; 543453Sgblack@eecs.umich.edu 553453Sgblack@eecs.umich.edumm::gp_t* mm::allocate() 562462SN/A{ 572SN/A gp_t* ptr; 58715SN/A if (free_list) 59715SN/A { 60715SN/A ptr = free_list->trans; 61715SN/A empties = free_list; 622SN/A free_list = free_list->next; 632SN/A } 643960Sgblack@eecs.umich.edu else 653960Sgblack@eecs.umich.edu { 663960Sgblack@eecs.umich.edu ptr = new gp_t(this); 674182Sgblack@eecs.umich.edu } 684182Sgblack@eecs.umich.edu return ptr; 694182Sgblack@eecs.umich.edu} 704182Sgblack@eecs.umich.edu 712680Sktlim@umich.eduvoid mm::free(gp_t* trans) 72237SN/A{ 732SN/A trans->reset(); // Delete auto extensions 742SN/A if (!empties) 752SN/A { 762SN/A empties = new access; 772SN/A empties->next = free_list; 782420SN/A empties->prev = 0; 792623SN/A if (free_list) 802SN/A free_list->prev = empties; 812107SN/A } 822159SN/A free_list = empties; 832455SN/A free_list->trans = trans; 842455SN/A empties = free_list->prev; 852386SN/A} 862623SN/A