3 void * pmc_alloc(unsigned int * numbytesallocated, unsigned int minimumbytes) {
4 unsigned int memcheck=minimumbytes>PMC_MINALLOC?minimumbytes:PMC_MINALLOC;
6 for(int i=0;i<NUMCORES4GC;i+=2) {
7 void *startptr=pmc_heapptr->regions[i].lastptr;
8 void *finishptr=pmc_heapptr->regions[i+1].lastptr;
10 if ((finishptr-startptr)>memcheck) {
11 struct pmc_region *region=&pmc_heapptr->regions[i];
12 tmc_spin_mutex_lock(®ion->lock);
13 startptr=region->lastptr;
15 //double check that we have the space
16 if ((finishptr-startptr)<memcheck)
18 unsigned int startindex=region->lowunit;
19 unsigned int endindex=pmc_heapptr->regions[i+1]->highunit;
20 void * newstartptr=startptr+memcheck;
22 //update unit end points
23 for(unsigned int index=startindex;index<endindex;index++) {
24 void *ptr=pmc_unitend(index);
25 if ((ptr>startptr)&&(ptr<newstartptr)) {
26 pmc_heapptr->units[index].endptr=newstartptr;
31 region->lastptr=newstartptr;
33 *numbytesallocated=(unsigned int)(newstartptr-startptr);
34 tmc_spin_mutex_unlock(®ion->lock);
37 tmc_spin_mutex_unlock(®ion->lock);