diff --git a/src/parallel/gitter_pll_mgb.cc b/src/parallel/gitter_pll_mgb.cc index 2998637fe60fb27a1a7dad33dfe54be968aa9f08..97ad7a119c84911a7529104753abef54bc896481 100644 --- a/src/parallel/gitter_pll_mgb.cc +++ b/src/parallel/gitter_pll_mgb.cc @@ -32,7 +32,7 @@ ParallelGridMover :: ParallelGridMover (BuilderIF & b, bool init) : MacroGridBui { // lock MyAlloc so that objects are not freed // because we want to reuse them - MyAlloc :: lockFree () ; + MyAlloc :: lockFree ((void *) this) ; if(init) initialize(); } @@ -74,7 +74,7 @@ inline ParallelGridMover :: ~ParallelGridMover () { assert(_initialized); // unlock MyAlloc so that objects can be freed again - MyAlloc :: unlockFree () ; + MyAlloc :: unlockFree ((void *) this) ; return ; } diff --git a/src/serial/myalloc.cc b/src/serial/myalloc.cc index 1a2b00592fc4dd5ad4f93cbe9dd013155b3b2a54..1c6ad78ae84a62e75046af23301f0a00929f6ff4 100644 --- a/src/serial/myalloc.cc +++ b/src/serial/myalloc.cc @@ -65,15 +65,23 @@ struct AllocEntry { // map holding AllocEntries for sizes static map < size_t, AllocEntry, less < size_t > > * freeStore = 0 ; +static set < void * > myAllocFreeLockers; -void MyAlloc :: lockFree () +void MyAlloc :: lockFree (void * addr) { + // remember address of locker + myAllocFreeLockers.insert( addr ); _freeAllowed = false; } -void MyAlloc :: unlockFree () +void MyAlloc :: unlockFree (void * addr) { - _freeAllowed = true; + myAllocFreeLockers.erase( addr ); + // only if no-one else has locked + if( myAllocFreeLockers.empty () ) + { + _freeAllowed = true; + } } void * MyAlloc :: operator new (size_t s) throw (OutOfMemoryException) diff --git a/src/serial/myalloc.h b/src/serial/myalloc.h index 672d464bc2261faadf7728dc481abce63a3121d6..5d11fb3079342610e131636aa525716be7915e20 100644 --- a/src/serial/myalloc.h +++ b/src/serial/myalloc.h @@ -44,10 +44,10 @@ class MyAlloc { friend class Initializer; // if called, freeing objects is allowed again - static void unlockFree(); + static void unlockFree(void *); // if called free of objects is not allowed - static void lockFree (); + static void lockFree (void *); protected : MyAlloc () {} ~MyAlloc () {}