ClPtrT clMemPartRealloc(ClMemPartHandleT handle, ClPtrT memBase, ClUint32T size) { MEM_PART_STATS memPartStats; ClPtrT mem = NULL; ClMemPartT *pMemPart = NULL; ClRcT rc = CL_OK; if(!(pMemPart = (ClMemPartT*)handle) ) return NULL; if(!size) size = 16; clOsalMutexLock(&pMemPart->mutex); if(memPartInfoGet(pMemPart->partId, &memPartStats) == ERROR) { clOsalMutexUnlock(&pMemPart->mutex); CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("memPartInfoGet for size [%d] failed with [%s]\n", size, strerror(errno))); return mem; } if(size >= memPartStats.numBytesFree) { if( (rc = clMemPartExpand(pMemPart, CL_MEM_PART_EXPANSION_SIZE) ) != CL_OK) { /* do nothing now and fall back to realloc.*/ } } mem = memPartRealloc(pMemPart->partId, memBase, size); clOsalMutexUnlock(&pMemPart->mutex); if(!mem) { CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Mem part realloc failure for size [%d]\n", size)); CL_ASSERT(0); } return mem; }
/*-------------------------------------------------------- */ void * realloc(void *ptr, size_t nBytes) { return memPartRealloc(memSysPartId,ptr,nBytes); }