cmMem: Added cmThPtrCAS() to allow mutlithread alloc.

This commit is contained in:
kpl 2012-11-23 21:29:30 -08:00
parent b7191065bb
commit fd40c2a213

23
cmMem.c
View File

@ -5,6 +5,7 @@
#include "cmMem.h"
#include "cmFloatTypes.h"
#include "cmMath.h"
#include "cmThread.h"
// Block layout
//
@ -449,8 +450,14 @@ void* cmMmAllocate(
{
cmErrMsg(&p->err,kOkMmRC,"Breakpoint for memory allocation id:%i.",p->nextId);
}
if( (long long)_cmMmDataToBasePtr(ndp,p->guardByteCnt) == 0x7fffed8d0b40 )
{
cmErrMsg(&p->err,kOkMmRC,"Breakpoint for memory allocation id:%i.",p->nextId);
}
*/
// if we are tracking changes
if( cmIsFlag(p->flags,kTrackMmFl) )
{
@ -470,23 +477,27 @@ void* cmMmAllocate(
return ndp;
}
cmThUIntIncr(&p->nextId,1);
// initialize the new tracking recd
rp->uniqueId = p->nextId;
rp->dataPtr = ndp;
rp->dataByteCnt = newByteCnt;
rp->fileLine = fileLine;
rp->fileNameStr = fileName;
rp->funcNameStr = funcName;
rp->flags = 0;
rp->uniqueId = p->nextId;
cmMmRecd_t *oldp, *newp;
do
{
oldp = p->listPtr;
newp = rp;
rp->linkPtr = p->listPtr;
//printf("%i %i %s %i %s\n",rp->uniqueId,newByteCnt,funcName,fileLine,fileName);
p->listPtr = rp;
}while(!cmThPtrCAS(&p->listPtr,oldp,newp));
assert( _cmMmCheckGuards(p,rp) == kOkMmRC );
++p->nextId;
}
else // a reallocation occurred.
if( orgDataPtr == ndp )