changeset 22:fef69b887df4 test_without_inline

Working version of singleton! Woohoo. Messes with return addr on stack.
author Me
date Sat, 13 Nov 2010 15:19:18 -0800
parents ad29ff7a0209
children 72b8d73c324d
files SSR.h SSR_Request_Handlers.c SSR_lib.c
diffstat 3 files changed, 38 insertions(+), 23 deletions(-) [+]
line diff
     1.1 --- a/SSR.h	Sat Nov 13 14:38:33 2010 -0800
     1.2 +++ b/SSR.h	Sat Nov 13 15:19:18 2010 -0800
     1.3 @@ -37,9 +37,9 @@
     1.4  
     1.5  typedef struct
     1.6   {
     1.7 +   void           *endInstrAddr;
     1.8     int32           hasBeenStarted;
     1.9     int32           hasFinished;
    1.10 -   void           *endInstrAddr;
    1.11     PrivQueueStruc *waitQ;
    1.12   }
    1.13  SSRSingleton;
    1.14 @@ -80,7 +80,7 @@
    1.15     void              *ptrToFree;
    1.16  
    1.17     int32              singletonID;
    1.18 -   SSRSingleton     **singletonAddr;
    1.19 +   SSRSingleton     **singletonPtrAddr;
    1.20  
    1.21     PtrToAtomicFn      fnToExecInMaster;
    1.22     void              *dataForFn;
     2.1 --- a/SSR_Request_Handlers.c	Sat Nov 13 14:38:33 2010 -0800
     2.2 +++ b/SSR_Request_Handlers.c	Sat Nov 13 15:19:18 2010 -0800
     2.3 @@ -407,16 +407,16 @@
     2.4                        SSRSemEnv *semEnv )
     2.5   { SSRSingleton *singleton;
     2.6  
     2.7 -   if( *(semReq->singletonAddr) == NULL )
     2.8 +   if( *(semReq->singletonPtrAddr) == NULL )
     2.9      { singleton                 = VMS__malloc( sizeof(SSRSingleton) );
    2.10        singleton->waitQ          = makeVMSPrivQ();
    2.11        singleton->endInstrAddr   = 0x0;
    2.12        singleton->hasBeenStarted = FALSE;
    2.13        singleton->hasFinished    = FALSE;
    2.14 -      *(semReq->singletonAddr)  = singleton;
    2.15 +      *(semReq->singletonPtrAddr)  = singleton;
    2.16      }
    2.17     else
    2.18 -      singleton = *(semReq->singletonAddr);
    2.19 +      singleton = *(semReq->singletonPtrAddr);
    2.20     handleStartSingleton_helper( singleton, requestingPr, semEnv );
    2.21   }
    2.22  
    2.23 @@ -462,7 +462,7 @@
    2.24   {
    2.25     SSRSingleton   *singleton;
    2.26  
    2.27 -   singleton = *(semReq->singletonAddr);
    2.28 +   singleton = *(semReq->singletonPtrAddr);
    2.29     handleEndSingleton_helper( singleton, requestingPr, semEnv );
    2.30    }
    2.31  
     3.1 --- a/SSR_lib.c	Sat Nov 13 14:38:33 2010 -0800
     3.2 +++ b/SSR_lib.c	Sat Nov 13 15:19:18 2010 -0800
     3.3 @@ -526,18 +526,24 @@
     3.4  
     3.5        //
     3.6     reqData.reqType       = singleton_data_start;
     3.7 -   reqData.singletonAddr = singletonAddr;
     3.8 +   reqData.singletonPtrAddr = singletonAddr;
     3.9  
    3.10     VMS__send_sem_request( &reqData, animPr );
    3.11 -   if( animPr->dataRetFromReq ) //either 0 or addr of label in end singleton
    3.12 -    { animPr->procrID += 10000;
    3.13 -      asm volatile("movl         %0,      %%eax;  \
    3.14 -                    jmp                  *%%eax"  \
    3.15 +   if( animPr->dataRetFromReq ) //either 0 or end singleton's return addr
    3.16 +    {    //Assembly code changes the return addr on the stack to the one
    3.17 +         // saved into the singleton by the end-singleton-fn
    3.18 +         //The return addr is at 0x4(%%ebp)
    3.19 +      asm volatile("movl        %0,      %%eax;   \
    3.20 +                    movl    (%%eax),     %%ebx;   \
    3.21 +                    movl    (%%ebx),     %%eax;   \
    3.22 +                    movl     %%eax,  0x4(%%ebp);" \
    3.23        /* outputs */ :                             \
    3.24 -      /* inputs  */ : "m"(animPr->dataRetFromReq) \
    3.25 +      /* inputs  */ : "m"(singletonAddr) \
    3.26        /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx","%edi","%esi"\
    3.27                     );
    3.28      }
    3.29 +   //now, simply return
    3.30 +   //will exit either from the start singleton call or the end-singleton call
    3.31   }
    3.32  
    3.33  /*Uses ID as index into array of flags.  If flag already set, resumes from
    3.34 @@ -566,25 +572,34 @@
    3.35   }
    3.36  
    3.37  void
    3.38 -SSR__end_data_singleton(  SSRSingleton **singletonAddr, VirtProcr *animPr )
    3.39 +SSR__end_data_singleton(  SSRSingleton **singletonPtrAddr, VirtProcr *animPr )
    3.40   {
    3.41     SSRSemReq  reqData;
    3.42  
    3.43        //don't need this addr until after singleton struct has reached
    3.44        // this function for first time
    3.45 -//   write_return_addr_into_singleton( (*(singletonAddr))->endInstrAddr );
    3.46 -   (*(singletonAddr))->endInstrAddr =  &&EndDataSingletonInstrAddr;
    3.47 +      //do assembly that saves the return addr of this fn call into the
    3.48 +      // data singleton -- that data-singleton can only be given to exactly
    3.49 +      // one instance in the code of this function.  However, can use this
    3.50 +      // function in different places for different data-singletons.
    3.51 +//   (*(singletonAddr))->endInstrAddr =  &&EndDataSingletonInstrAddr;
    3.52  
    3.53 -   reqData.reqType     = singleton_data_end;
    3.54 -   reqData.singletonAddr = singletonAddr;
    3.55 +         //Assembly code takes the return addr off the stack and saves
    3.56 +         // into the singleton.  The first position in the singleton is the
    3.57 +         // "endInstrAddr" field, and the return addr is at 0x4(%%ebp)
    3.58 +      asm volatile("movl 0x4(%%ebp),     %%eax;   \
    3.59 +                    movl        %0,      %%ebx;   \
    3.60 +                    movl    (%%ebx),     %%ecx;   \
    3.61 +                    movl     %%eax,     (%%ecx);" \
    3.62 +      /* outputs */ :                             \
    3.63 +      /* inputs  */ : "m"(singletonPtrAddr) \
    3.64 +      /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx","%edi","%esi"\
    3.65 +                   );
    3.66 +
    3.67 +   reqData.reqType          = singleton_data_end;
    3.68 +   reqData.singletonPtrAddr = singletonPtrAddr;
    3.69  
    3.70     VMS__send_sem_request( &reqData, animPr );
    3.71 -   printf("foo");
    3.72 -   return;
    3.73 -EndDataSingletonInstrAddr:
    3.74 -   printf("bar");
    3.75 -   animPr->procrID += 2000;
    3.76 -   return;
    3.77   }
    3.78  
    3.79  /*This executes the function in the masterVP, so it executes in isolation