2 #include "pmc_garbage.h"
5 void * pmc_alloc(unsigned int * numbytesallocated, unsigned int minimumbytes) {
6 unsigned int memcheck=minimumbytes>PMC_MINALLOC?minimumbytes:PMC_MINALLOC;
8 for(int i=0;i<NUMCORES4GC;i+=2) {
9 void *startptr=pmc_heapptr->regions[i].lastptr;
10 void *finishptr=pmc_heapptr->regions[i+1].lastptr;
12 if ((finishptr-startptr)>memcheck) {
13 struct pmc_region *region=&pmc_heapptr->regions[i];
14 tmc_spin_mutex_lock(®ion->lock);
15 startptr=region->lastptr;
17 //double check that we have the space
18 if ((finishptr-startptr)<memcheck)
20 unsigned int startindex=region->lowunit;
21 unsigned int endindex=pmc_heapptr->regions[i+1].highunit;
22 void * newstartptr=startptr+memcheck;
24 //update unit end points
25 for(unsigned int index=startindex;index<endindex;index++) {
26 void *ptr=pmc_unitend(index);
27 if ((ptr>startptr)&&(ptr<newstartptr)) {
28 pmc_heapptr->units[index].endptr=newstartptr;
33 region->lastptr=newstartptr;
35 *numbytesallocated=(unsigned int)(newstartptr-startptr);
36 tmc_spin_mutex_unlock(®ion->lock);
39 tmc_spin_mutex_unlock(®ion->lock);