diff VMS.c @ 30:c8823e0bb2b4

Started adding own version of malloc and free Just in case they're using TLS and causing the issues
author Me
date Mon, 09 Aug 2010 02:24:31 -0700
parents 0e008278fe3c
children e69579a0e797 65e5918731b8
line diff
     1.1 --- a/VMS.c	Wed Jul 28 13:12:10 2010 -0700
     1.2 +++ b/VMS.c	Mon Aug 09 02:24:31 2010 -0700
     1.3 @@ -100,8 +100,49 @@
     1.4     writeVMSQ( masterEnv->masterVirtPr, workQ );
     1.5  
     1.6     numProcrsCreated = 1;  //global counter for debugging
     1.7 +
     1.8 +   //==================== malloc substitute ========================
     1.9 +   //
    1.10 +   //Testing whether malloc is using thread-local storage and therefore
    1.11 +   // causing unreliable behavior.
    1.12 +   //Just allocate a massive chunk of memory and roll own malloc/free and
    1.13 +   // make app use VMS__malloc_to, which will suspend and perform malloc
    1.14 +   // in the master, taking from this massive chunk.
    1.15 +
    1.16 +//   initFreeList();
    1.17   }
    1.18  
    1.19 +/*
    1.20 +void
    1.21 +initMasterMalloc()
    1.22 + {
    1.23 +   _VMSMasterEnv->mallocChunk = malloc( MASSIVE_MALLOC_SIZE );
    1.24 +
    1.25 +      //The free-list element is the first several locations of an
    1.26 +      // allocated chunk -- the address given to the application is pre-
    1.27 +      // pended with both the ownership structure and the free-list struc.
    1.28 +      //So, write the values of these into the first locations of
    1.29 +      // mallocChunk -- which marks it as free & puts in its size.
    1.30 +   listElem = (FreeListElem *)_VMSMasterEnv->mallocChunk;
    1.31 +   listElem->size = MASSIVE_MALLOC_SIZE - NUM_PREPEND_BYTES
    1.32 +   listElem->next = NULL;
    1.33 + }
    1.34 +
    1.35 +void
    1.36 +dissipateMasterMalloc()
    1.37 + {
    1.38 +      //Just foo code -- to get going -- doing as if free list were link-list
    1.39 +   currElem = _VMSMasterEnv->freeList;
    1.40 +   while( currElem != NULL )
    1.41 +    {
    1.42 +      nextElem = currElem->next;
    1.43 +      masterFree( currElem );
    1.44 +      currElem = nextElem;
    1.45 +    }
    1.46 +   free( _VMSMasterEnv->freeList );
    1.47 + }
    1.48 + */
    1.49 +
    1.50  void
    1.51  create_sched_slots( MasterEnv *masterEnv )
    1.52   { SchedSlot  **schedSlots, **filledSlots;
    1.53 @@ -551,7 +592,7 @@
    1.54   *This function has the sole purpose of setting the stack and framePtr
    1.55   * to the coreLoop's stack and framePtr.. it does that then jumps to the
    1.56   * core loop's shutdown point -- might be able to just call Pthread_exit
    1.57 - * from here, but going back to the pthread's stack and setting everything
    1.58 + * from here, but am going back to the pthread's stack and setting everything
    1.59   * up just as if it never jumped out, before calling pthread_exit.
    1.60   *The end-point of core loop will free the stack and so forth of the
    1.61   * processor that animates this function, (this fn is transfering the
    1.62 @@ -580,7 +621,9 @@
    1.63  
    1.64  
    1.65  
    1.66 -/*This is called has to free anything allocated during VMS_init, and any other alloc'd
    1.67 +/*This is called after the threads have shut down and control as returned
    1.68 + * to the semantic layer, in the entry point function in the main thread.
    1.69 + * It has to free anything allocated during VMS_init, and any other alloc'd
    1.70   * locations that might be left over.
    1.71   */
    1.72  void