Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
diff vmalloc.c @ 53:42dd44df1bb0
Init changed to only use VMS__malloc & uses VMS__malloc versions of utilities
| author | Me |
|---|---|
| date | Mon, 01 Nov 2010 21:21:32 -0700 |
| parents | 8f7141a9272e |
| children | 3bac84e4e56e |
line diff
1.1 --- a/vmalloc.c Sat Oct 30 21:53:55 2010 -0700 1.2 +++ b/vmalloc.c Mon Nov 01 21:21:32 2010 -0700 1.3 @@ -8,6 +8,7 @@ 1.4 */ 1.5 1.6 #include <malloc.h> 1.7 +#include <stdlib.h> 1.8 1.9 #include "VMS.h" 1.10 1.11 @@ -123,14 +124,19 @@ 1.12 { MallocProlog *elemToFree, *nextLowerElem, *nextHigherElem; 1.13 int32 lowerExistsAndIsFree, higherExistsAndIsFree, sizeOfElem; 1.14 1.15 - if( ptrToFree < _VMSMasterEnv->freeListHead->nextLowerInMem || 1.16 - ptrToFree > _VMSMasterEnv->freeListHead->nextHigherInMem ) 1.17 + if( ptrToFree < (void*)_VMSMasterEnv->freeListHead->nextLowerInMem || 1.18 + ptrToFree > (void*)_VMSMasterEnv->freeListHead->nextHigherInMem ) 1.19 { //outside the range of data owned by VMS's malloc, so do nothing 1.20 return; 1.21 } 1.22 //subtract size of prolog to get pointer to prolog, then cast 1.23 elemToFree = (MallocProlog *)((char *)ptrToFree - sizeof(MallocProlog)); 1.24 sizeOfElem =(int32)((char*)elemToFree->nextHigherInMem-(char*)elemToFree); 1.25 + 1.26 + if( elemToFree->prevChunkInFreeList != NULL ) 1.27 + { printf( "error: freeing same element twice!" ); exit(1); 1.28 + } 1.29 + 1.30 _VMSMasterEnv->amtOfOutstandingMem -= sizeOfElem; 1.31 1.32 nextLowerElem = elemToFree->nextLowerInMem; 1.33 @@ -209,10 +215,73 @@ 1.34 } 1.35 1.36 1.37 +/*Allocates memory from the external system -- higher overhead 1.38 + * 1.39 + *Because of Linux's malloc throwing bizarre random faults when malloc is 1.40 + * used inside a VMS virtual processor, have to pass this as a request and 1.41 + * have the core loop do it when it gets around to it -- will look for these 1.42 + * chores leftover from the previous animation of masterVP the next time it 1.43 + * goes to animate the masterVP -- so it takes two separate masterVP 1.44 + * animations, separated by work, to complete an external malloc or 1.45 + * external free request. 1.46 + * 1.47 + *Thinking core loop accepts signals -- just looks if signal-location is 1.48 + * empty or not -- 1.49 + */ 1.50 +void * 1.51 +VMS__malloc_in_ext( int32 sizeRequested ) 1.52 + { 1.53 + /* 1.54 + //This is running in the master, so no chance for multiple cores to be 1.55 + // competing for the core's flag. 1.56 + if( *(_VMSMasterEnv->coreLoopSignalAddr[ 0 ]) != 0 ) 1.57 + { //something has already signalled to core loop, so save the signal 1.58 + // and look, next time master animated, to see if can send it. 1.59 + //Note, the addr to put a signal is in the coreloop's frame, so just 1.60 + // checks it each time through -- make it volatile to avoid GCC 1.61 + // optimizations -- it's a coreloop local var that only changes 1.62 + // after jumping away. The signal includes the addr to send the 1.63 + //return to -- even if just empty return completion-signal 1.64 + // 1.65 + //save the signal in some queue that the master looks at each time 1.66 + // it starts up -- one loc says if empty for fast common case -- 1.67 + //something like that -- want to hide this inside this call -- but 1.68 + // think this has to come as a request -- req handler gives procr 1.69 + // back to master loop, which gives it back to req handler at point 1.70 + // it sees that core loop has sent return signal. Something like 1.71 + // that. 1.72 + saveTheSignal 1.73 + 1.74 + } 1.75 + coreSigData->type = malloc; 1.76 + coreSigData->sizeToMalloc = sizeRequested; 1.77 + coreSigData->locToSignalCompletion = &figureOut; 1.78 + _VMSMasterEnv->coreLoopSignals[ 0 ] = coreSigData; 1.79 + */ 1.80 + //just risk system-stack faults until get this figured out 1.81 + return malloc( sizeRequested ); 1.82 + } 1.83 + 1.84 + 1.85 +/*Frees memory that was allocated in the external system -- higher overhead 1.86 + * 1.87 + *As noted in external malloc comment, this is clunky 'cause the free has 1.88 + * to be called in the core loop. 1.89 + */ 1.90 +void 1.91 +VMS__free_in_ext( void *ptrToFree ) 1.92 + { 1.93 + //just risk system-stack faults until get this figured out 1.94 + free( ptrToFree ); 1.95 + 1.96 + //TODO: fix this -- so 1.97 + } 1.98 + 1.99 + 1.100 /*Designed to be called from the main thread outside of VMS, during init 1.101 */ 1.102 MallocProlog * 1.103 -VMS__create_free_list() 1.104 +VMS_ext__create_free_list() 1.105 { MallocProlog *freeListHead, *firstChunk; 1.106 1.107 //Note, this is running in the main thread -- all increases in malloc 1.108 @@ -226,16 +295,18 @@ 1.109 //Use this addr to free the heap when cleanup 1.110 freeListHead->nextLowerInMem = firstChunk; 1.111 //to identify top-of-heap elem, compare this addr to elem's next higher 1.112 - freeListHead->nextHigherInMem = (char *)firstChunk + 1.113 - MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE; 1.114 + freeListHead->nextHigherInMem = (void*)( (char*)firstChunk + 1.115 + MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE); 1.116 freeListHead->nextChunkInFreeList = firstChunk; 1.117 1.118 firstChunk->nextChunkInFreeList = NULL; 1.119 firstChunk->prevChunkInFreeList = freeListHead; 1.120 //next Higher has to be set to top of chunk, so can calc size in malloc 1.121 - firstChunk->nextHigherInMem = (char *)firstChunk + 1.122 - MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE; 1.123 + firstChunk->nextHigherInMem = (void*)( (char*)firstChunk + 1.124 + MALLOC_ADDITIONAL_MEM_FROM_OS_SIZE); 1.125 firstChunk->nextLowerInMem = NULL; //identifies as bott of heap 1.126 + 1.127 + _VMSMasterEnv->amtOfOutstandingMem = 0; //none allocated yet 1.128 1.129 return freeListHead; 1.130 }
