cmMem: Added cmThPtrCAS() to allow mutlithread alloc.
This commit is contained in:
parent
b7191065bb
commit
fd40c2a213
23
cmMem.c
23
cmMem.c
@ -5,6 +5,7 @@
|
|||||||
#include "cmMem.h"
|
#include "cmMem.h"
|
||||||
#include "cmFloatTypes.h"
|
#include "cmFloatTypes.h"
|
||||||
#include "cmMath.h"
|
#include "cmMath.h"
|
||||||
|
#include "cmThread.h"
|
||||||
|
|
||||||
// Block layout
|
// Block layout
|
||||||
//
|
//
|
||||||
@ -449,8 +450,14 @@ void* cmMmAllocate(
|
|||||||
{
|
{
|
||||||
cmErrMsg(&p->err,kOkMmRC,"Breakpoint for memory allocation id:%i.",p->nextId);
|
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 we are tracking changes
|
||||||
if( cmIsFlag(p->flags,kTrackMmFl) )
|
if( cmIsFlag(p->flags,kTrackMmFl) )
|
||||||
{
|
{
|
||||||
@ -470,23 +477,27 @@ void* cmMmAllocate(
|
|||||||
return ndp;
|
return ndp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmThUIntIncr(&p->nextId,1);
|
||||||
|
|
||||||
// initialize the new tracking recd
|
// initialize the new tracking recd
|
||||||
rp->uniqueId = p->nextId;
|
|
||||||
rp->dataPtr = ndp;
|
rp->dataPtr = ndp;
|
||||||
rp->dataByteCnt = newByteCnt;
|
rp->dataByteCnt = newByteCnt;
|
||||||
rp->fileLine = fileLine;
|
rp->fileLine = fileLine;
|
||||||
rp->fileNameStr = fileName;
|
rp->fileNameStr = fileName;
|
||||||
rp->funcNameStr = funcName;
|
rp->funcNameStr = funcName;
|
||||||
rp->flags = 0;
|
rp->flags = 0;
|
||||||
|
rp->uniqueId = p->nextId;
|
||||||
|
|
||||||
|
cmMmRecd_t *oldp, *newp;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
oldp = p->listPtr;
|
||||||
|
newp = rp;
|
||||||
rp->linkPtr = p->listPtr;
|
rp->linkPtr = p->listPtr;
|
||||||
|
}while(!cmThPtrCAS(&p->listPtr,oldp,newp));
|
||||||
//printf("%i %i %s %i %s\n",rp->uniqueId,newByteCnt,funcName,fileLine,fileName);
|
|
||||||
|
|
||||||
p->listPtr = rp;
|
|
||||||
|
|
||||||
assert( _cmMmCheckGuards(p,rp) == kOkMmRC );
|
assert( _cmMmCheckGuards(p,rp) == kOkMmRC );
|
||||||
|
|
||||||
++p->nextId;
|
|
||||||
}
|
}
|
||||||
else // a reallocation occurred.
|
else // a reallocation occurred.
|
||||||
if( orgDataPtr == ndp )
|
if( orgDataPtr == ndp )
|
||||||
|
Loading…
Reference in New Issue
Block a user