Explorar el Código

cmMem: Added cmThPtrCAS() to allow mutlithread alloc.

master
kpl hace 11 años
padre
commit
fd40c2a213
Se han modificado 1 ficheros con 25 adiciones y 14 borrados
  1. 25
    14
      cmMem.c

+ 25
- 14
cmMem.c Ver fichero

5
 #include "cmMem.h"
5
 #include "cmMem.h"
6
 #include "cmFloatTypes.h"
6
 #include "cmFloatTypes.h"
7
 #include "cmMath.h"
7
 #include "cmMath.h"
8
+#include "cmThread.h"
8
 
9
 
9
 // Block layout
10
 // Block layout
10
 //
11
 //
431
 { return h.h != NULL; }
432
 { return h.h != NULL; }
432
 
433
 
433
 void* cmMmAllocate(     
434
 void* cmMmAllocate(     
434
-  cmMmH_t     h, 
435
-  void*       orgDataPtr, 
436
-  unsigned    newEleCnt,
437
-  unsigned    newEleByteCnt, 
438
-  enum cmMmAllocFlags_t    flags, 
439
-  const char* fileName, 
440
-  const char* funcName, 
441
-  unsigned    fileLine )
435
+  cmMmH_t               h, 
436
+  void*                 orgDataPtr, 
437
+  unsigned              newEleCnt,
438
+  unsigned              newEleByteCnt, 
439
+  enum cmMmAllocFlags_t flags, 
440
+  const char*           fileName, 
441
+  const char*           funcName, 
442
+  unsigned              fileLine )
442
 {
443
 {
443
    cmMm_t*  p          = _cmMmHandleToPtr(h); 
444
    cmMm_t*  p          = _cmMmHandleToPtr(h); 
444
    unsigned newByteCnt = newEleCnt * newEleByteCnt;
445
    unsigned newByteCnt = newEleCnt * newEleByteCnt;
449
    {
450
    {
450
      cmErrMsg(&p->err,kOkMmRC,"Breakpoint for memory allocation id:%i.",p->nextId);
451
      cmErrMsg(&p->err,kOkMmRC,"Breakpoint for memory allocation id:%i.",p->nextId);
451
    }
452
    }
453
+
454
+   if( (long long)_cmMmDataToBasePtr(ndp,p->guardByteCnt) == 0x7fffed8d0b40 )
455
+   {
456
+     cmErrMsg(&p->err,kOkMmRC,"Breakpoint for memory allocation id:%i.",p->nextId);
457
+   }
452
    */
458
    */
453
 
459
 
460
+
454
    // if we are tracking changes
461
    // if we are tracking changes
455
    if( cmIsFlag(p->flags,kTrackMmFl) )
462
    if( cmIsFlag(p->flags,kTrackMmFl) )
456
    {
463
    {
470
          return ndp;
477
          return ndp;
471
        }
478
        }
472
 
479
 
480
+       cmThUIntIncr(&p->nextId,1);
481
+
473
        // initialize the new tracking recd
482
        // initialize the new tracking recd
474
-       rp->uniqueId     = p->nextId;
475
        rp->dataPtr      = ndp;
483
        rp->dataPtr      = ndp;
476
        rp->dataByteCnt  = newByteCnt;
484
        rp->dataByteCnt  = newByteCnt;
477
        rp->fileLine     = fileLine;
485
        rp->fileLine     = fileLine;
478
        rp->fileNameStr  = fileName;
486
        rp->fileNameStr  = fileName;
479
        rp->funcNameStr  = funcName;
487
        rp->funcNameStr  = funcName;
480
        rp->flags        = 0;
488
        rp->flags        = 0;
481
-       rp->linkPtr      = p->listPtr;
482
-
483
-       //printf("%i %i %s %i %s\n",rp->uniqueId,newByteCnt,funcName,fileLine,fileName);
489
+       rp->uniqueId     = p->nextId;
484
 
490
 
485
-       p->listPtr = rp;
491
+       cmMmRecd_t *oldp, *newp;
492
+       do
493
+       {
494
+         oldp         = p->listPtr;
495
+         newp         = rp;
496
+         rp->linkPtr  = p->listPtr;
497
+       }while(!cmThPtrCAS(&p->listPtr,oldp,newp));
486
 
498
 
487
        assert( _cmMmCheckGuards(p,rp) == kOkMmRC );
499
        assert( _cmMmCheckGuards(p,rp) == kOkMmRC );
488
 
500
 
489
-       ++p->nextId;
490
      }
501
      }
491
      else // a reallocation occurred.
502
      else // a reallocation occurred.
492
        if( orgDataPtr == ndp )
503
        if( orgDataPtr == ndp )

Loading…
Cancelar
Guardar