From d59d1ad23afbc70c4b57a60c4b8a310d5d95a165 Mon Sep 17 00:00:00 2001 From: Christian Engwer <christi@dune-project.org> Date: Mon, 12 Feb 2018 23:32:15 +0100 Subject: [PATCH] [memory] the mgheapmgr used two global variables, we move them to the heap these variables were used to chnage the memory mangement of a particular UG instance. As these variables were global, this could only work by coincedence. We moved them to the heap, as this is the memory mangement unit for the multi grid. --- gm/algebra.cc | 5 +++-- gm/mgheapmgr.cc | 14 +++----------- gm/mgheapmgr.h | 18 ------------------ gm/ugm.cc | 4 ++-- low/heaps.cc | 5 +++++ low/heaps.h | 8 ++++++++ 6 files changed, 21 insertions(+), 33 deletions(-) diff --git a/gm/algebra.cc b/gm/algebra.cc index 64162aa1f..fa1ad113b 100644 --- a/gm/algebra.cc +++ b/gm/algebra.cc @@ -2504,8 +2504,9 @@ INT NS_DIM_PREFIX MGCreateConnection (MULTIGRID *theMG) #ifdef DYNAMIC_MEMORY_ALLOCMODEL if (theMG->bottomtmpmem) return(0); - usefreelistmemory = 0; - if (Mark(MGHEAP(theMG),FROM_BOTTOM,&freelist_end_mark)) REP_ERR_RETURN(1); + MGHEAP(theMG)->usefreelistmemory = 0; + if (Mark(MGHEAP(theMG),FROM_BOTTOM,&(MGHEAP(theMG)->freelist_end_mark))) + REP_ERR_RETURN(1); theMG->bottomtmpmem = 1; #endif diff --git a/gm/mgheapmgr.cc b/gm/mgheapmgr.cc index 5162314ef..4b1d39f32 100644 --- a/gm/mgheapmgr.cc +++ b/gm/mgheapmgr.cc @@ -56,15 +56,6 @@ USING_UG_NAMESPACES /* */ /****************************************************************************/ -/****************************************************************************/ -/* */ -/* definition of exported global variables */ -/* */ -/****************************************************************************/ - -INT NS_DIM_PREFIX usefreelistmemory = 1; -INT NS_DIM_PREFIX freelist_end_mark = 0; - /****************************************************************************/ /* */ /* definition of variables global to this source file only (static!) */ @@ -101,8 +92,9 @@ INT NS_DIM_PREFIX DisposeBottomHeapTmpMemory (MULTIGRID *theMG) if (DisposeConnectionsFromMultiGrid(theMG)) REP_ERR_RETURN(1); theMG->bottomtmpmem = 0; - if (Release(MGHEAP(theMG),FROM_BOTTOM,freelist_end_mark)) REP_ERR_RETURN(1); - usefreelistmemory = 1; + if (Release(MGHEAP(theMG),FROM_BOTTOM,MGHEAP(theMG)->freelist_end_mark)) + REP_ERR_RETURN(1); + MGHEAP(theMG)->usefreelistmemory = 1; return(0); } diff --git a/gm/mgheapmgr.h b/gm/mgheapmgr.h index 7a535c53f..a9078d490 100644 --- a/gm/mgheapmgr.h +++ b/gm/mgheapmgr.h @@ -52,24 +52,6 @@ START_UGDIM_NAMESPACE -/****************************************************************************/ -/* */ -/* data structures exported by the corresponding source file */ -/* */ -/****************************************************************************/ - - - -/****************************************************************************/ -/* */ -/* definition of exported global variables */ -/* */ -/****************************************************************************/ - -extern INT usefreelistmemory; -extern INT freelist_end_mark; - - /****************************************************************************/ /* */ /* function declarations */ diff --git a/gm/ugm.cc b/gm/ugm.cc index 47f82fa11..31d7ac755 100644 --- a/gm/ugm.cc +++ b/gm/ugm.cc @@ -311,7 +311,7 @@ void * NS_DIM_PREFIX GetMemoryForObjectNew (HEAP *theHeap, INT size, INT type) check_of_getcallstack = 1; #endif - if (usefreelistmemory == 1) + if (theHeap->usefreelistmemory == 1) obj = GetFreelistMemory(theHeap, size); else { @@ -401,7 +401,7 @@ INT NS_DIM_PREFIX PutFreeObjectNew (HEAP *theHeap, void *object, INT size, INT t check_of_putcallstack = 1; #endif - if (usefreelistmemory == 1) + if (theHeap->usefreelistmemory == 1) { err = PutFreelistMemory(theHeap, object, size); #ifdef Debug diff --git a/low/heaps.cc b/low/heaps.cc index 82894a3d3..a20e996ec 100644 --- a/low/heaps.cc +++ b/low/heaps.cc @@ -207,6 +207,11 @@ HEAP *NS_PREFIX NewHeap (enum HeapType type, MEM size, void *buffer) new(theHeap->markedMemory) std::vector<void*>[MARK_STACK_SIZE]; #endif + /* initialize data variables needed for bottom tmp memory management */ + theHeap->usefreelistmemory = 1; + theHeap->freelist_end_mark = 0; + + /* return heap structure */ return(theHeap); } diff --git a/low/heaps.h b/low/heaps.h index db1ba8f53..1ea042b5c 100644 --- a/low/heaps.h +++ b/low/heaps.h @@ -150,6 +150,14 @@ typedef struct { /* This is used only if UG_USE_SYSTEM_HEAP is set, but I don't want the * #ifdef in an installed header, hence the data member is there all the time. */ std::vector<void*> markedMemory[MARK_STACK_SIZE]; + + /* These were global variables needed for DYNAMIC_MEMORY_ALLOCMODEL + + we try to avoid global state, as it does not play well with multiple UG instances. + */ + INT usefreelistmemory; + INT freelist_end_mark; + } HEAP; /****************************************************************************/ -- GitLab