diff VSs.c @ 30:a40859b8dc33

ML_dev -- compiles and runs, may still have shutdown issues
author Sean Halle <seanhalle@yahoo.com>
date Sat, 02 Mar 2013 10:07:58 -0800
parents dd1efbf29ff9
children 0162554f6ef5
line diff
     1.1 --- a/VSs.c	Thu Feb 07 16:30:16 2013 -0800
     1.2 +++ b/VSs.c	Sat Mar 02 10:07:58 2013 -0800
     1.3 @@ -125,26 +125,6 @@
     1.4                                                          ANY_CORE, creatingThd );
     1.5   }
     1.6  
     1.7 -/* old version -- looks safe to delete
     1.8 -SlaveVP *
     1.9 -VSs__create_slave_with_affinity( TopLevelFnPtr fnPtr, void *initData,
    1.10 -                        SlaveVP *creatingSlv,  int32  coreToAssignOnto )
    1.11 - { VSsLangReq  reqData;
    1.12 -
    1.13 -      //the lang request data is on the stack and disappears when this
    1.14 -      // call returns -- it's guaranteed to remain in the VP's stack for as
    1.15 -      // long as the VP is suspended.
    1.16 -   reqData.reqType            = create_slave_w_aff; //not used, May 2012
    1.17 -   reqData.coreToAssignOnto   = coreToAssignOnto;
    1.18 -   reqData.fnPtr              = fnPtr;
    1.19 -   reqData.initData           = initData;
    1.20 -   reqData.callingSlv         = creatingSlv;
    1.21 -
    1.22 -   PR_WL__send_create_slaveVP_req( &reqData, creatingSlv, VSs_MAGIC_NUMBER );
    1.23 -
    1.24 -   return creatingSlv->dataRetFromReq;
    1.25 - }
    1.26 -*/
    1.27  
    1.28  
    1.29  SlaveVP *
    1.30 @@ -160,7 +140,7 @@
    1.31     reqData.fnPtr            = fnPtr;
    1.32     reqData.initData         = initData;
    1.33     
    1.34 -   PR_WL__send_create_slaveVP_req( &reqData, thdID, (CreateHandler)&handleCreateThd,
    1.35 +   PR_WL__send_create_slaveVP_req( &reqData, thdID, (CreateHandler)&VSs__handleCreateThd,
    1.36                                                  creatingThd, VSs_MAGIC_NUMBER );
    1.37     return (SlaveVP *)creatingThd->dataRetFromReq;
    1.38   }
    1.39 @@ -176,7 +156,7 @@
    1.40  VSs__end_thread( SlaveVP *thdToEnd )
    1.41   {    
    1.42     //the lang request is null for VSs version of end slave 
    1.43 -   PR_WL__send_end_slave_req( NULL, (RequestHandler)&handleDissipate, thdToEnd, 
    1.44 +   PR_WL__send_end_slave_req( NULL, (RequestHandler)&VSs__handleDissipate, thdToEnd, 
    1.45                                VSs_MAGIC_NUMBER );
    1.46   }
    1.47  
    1.48 @@ -202,7 +182,7 @@
    1.49        // top-level-fn of task and the data for that fn, plus lang's req,
    1.50        // animating slave, and lang's magic number
    1.51     PR_WL__send_create_task_req( taskType->fn, args, &reqData, NO_ID,
    1.52 -                                &handleSubmitTask, animSlv, VSs_MAGIC_NUMBER );
    1.53 +                                &VSs__handleSubmitTask, animSlv, VSs_MAGIC_NUMBER );
    1.54   }
    1.55  
    1.56  void
    1.57 @@ -212,12 +192,12 @@
    1.58   
    1.59     reqData.reqType    = submit_task;
    1.60     
    1.61 -   reqData.taskType   = taskType;
    1.62 +   reqData.taskType   = taskType; //VSs info about args, dependencies, etc
    1.63     reqData.args       = args;
    1.64     reqData.callingSlv = animSlv;
    1.65   
    1.66     PR_WL__send_create_task_req( taskType->fn, args, &reqData, taskID,
    1.67 -                                &handleSubmitTask, animSlv, VSs_MAGIC_NUMBER );
    1.68 +                                &VSs__handleSubmitTask, animSlv, VSs_MAGIC_NUMBER );
    1.69   }
    1.70  
    1.71  
    1.72 @@ -243,7 +223,7 @@
    1.73   { VSsLangReq  reqData;
    1.74     
    1.75     //VSs has nothing extra to communicate to end task handler, so lang req is NULL
    1.76 -   PR_WL__send_end_task_request( NULL, &handleEndTask, animSlv, VSs_MAGIC_NUMBER );
    1.77 +   PR_WL__send_end_task_request( NULL, &VSs__handleEndTask, animSlv, VSs_MAGIC_NUMBER );
    1.78   }
    1.79  
    1.80  
    1.81 @@ -258,11 +238,34 @@
    1.82     reqData.reqType      = taskwait;
    1.83     reqData.callingSlv   = animSlv;
    1.84     
    1.85 -   PR_WL__send_lang_request( &reqData, (RequestHandler)&handleTaskwait, animSlv,
    1.86 +   PR_WL__send_lang_request( &reqData, (RequestHandler)&VSs__handleTaskwait, animSlv,
    1.87                               VSs_MAGIC_NUMBER );
    1.88   }
    1.89  
    1.90 +void
    1.91 +VSs__wait_for_all_VSs_created_work_to_end( SlaveVP *seedSlv )
    1.92 + {
    1.93 +    VSsLangReq  reqData;
    1.94  
    1.95 +   reqData.reqType      = activity_cease_wait;
    1.96 +   reqData.callingSlv   = seedSlv;
    1.97 +   
    1.98 +   PR_WL__send_lang_request( &reqData, (RequestHandler)&VSs__handleWaitForVSsWorkToEnd, seedSlv,
    1.99 +                             VSs_MAGIC_NUMBER );   
   1.100 + }
   1.101 +
   1.102 +
   1.103 +
   1.104 +/*This is called by the application -- normally the seed slave.  It causes a
   1.105 + * request to be sent that frees the VSs lang env and all its contents.
   1.106 + *The seed slave resumes from the built-in PRServ langlet's environment.  It
   1.107 + * will be PRServ that causes return from this call.
   1.108 + */
   1.109 +void
   1.110 +VSs__shutdown( SlaveVP *seedSlv )
   1.111 + {
   1.112 +   PR_WL__send_lang_shutdown_request( seedSlv, VSs_MAGIC_NUMBER );   
   1.113 + }
   1.114  
   1.115  //==========================  send and receive ============================
   1.116  //
   1.117 @@ -270,8 +273,9 @@
   1.118  inline 
   1.119  int32 *
   1.120  VSs__give_self_taskID( SlaveVP *animSlv )
   1.121 - {
   1.122 -   return PR__give_ID_from_slave( animSlv, VSs_MAGIC_NUMBER );
   1.123 + { void *metaTask;
   1.124 +   metaTask = PR_WL__give_lang_meta_task_from_slave( animSlv, VSs_MAGIC_NUMBER );
   1.125 +   return PR__give_ID_from_lang_meta_task( metaTask );
   1.126   }
   1.127  
   1.128  //================================ send ===================================
   1.129 @@ -290,7 +294,7 @@
   1.130     
   1.131     reqData.nextReqInHashEntry = NULL;
   1.132  
   1.133 -   PR_WL__send_lang_request( &reqData, (RequestHandler)&handleSendTypeTo,
   1.134 +   PR_WL__send_lang_request( &reqData, (RequestHandler)&VSs__handleSendTypeTo,
   1.135                                                    senderSlv, VSs_MAGIC_NUMBER );
   1.136  
   1.137        //When come back from suspend, no longer own data reachable from msg
   1.138 @@ -309,7 +313,7 @@
   1.139  
   1.140     reqData.nextReqInHashEntry = NULL;
   1.141  
   1.142 -   PR_WL__send_lang_request( &reqData, (RequestHandler)&handleSendFromTo,
   1.143 +   PR_WL__send_lang_request( &reqData, (RequestHandler)&VSs__handleSendFromTo,
   1.144                                                    senderSlv, VSs_MAGIC_NUMBER );
   1.145   }
   1.146  
   1.147 @@ -335,7 +339,7 @@
   1.148     
   1.149     reqData.nextReqInHashEntry = NULL;
   1.150  
   1.151 -   PR_WL__send_lang_request( &reqData, (RequestHandler)&handleReceiveTypeTo,
   1.152 +   PR_WL__send_lang_request( &reqData, (RequestHandler)&VSs__handleReceiveTypeTo,
   1.153                                                  receiverSlv, VSs_MAGIC_NUMBER );
   1.154     
   1.155     return receiverSlv->dataRetFromReq;
   1.156 @@ -361,7 +365,7 @@
   1.157     reqData.nextReqInHashEntry = NULL;
   1.158        DEBUG__printf2(dbgRqstHdlr,"WL: receive from %d to: %d", reqData.senderID[1], reqData.receiverID[1]);
   1.159        
   1.160 -   PR_WL__send_lang_request( &reqData, (RequestHandler)&handleReceiveFromTo,
   1.161 +   PR_WL__send_lang_request( &reqData, (RequestHandler)&VSs__handleReceiveFromTo,
   1.162                               receiverSlv, VSs_MAGIC_NUMBER );
   1.163  
   1.164     return receiverSlv->dataRetFromReq;
   1.165 @@ -370,195 +374,4 @@
   1.166  
   1.167  
   1.168  
   1.169 -//==========================================================================
   1.170 -//
   1.171 -/*A function singleton is a function whose body executes exactly once, on a
   1.172 - * single core, no matter how many times the fuction is called and no
   1.173 - * matter how many cores or the timing of cores calling it.
   1.174 - *
   1.175 - *A data singleton is a ticket attached to data.  That ticket can be used
   1.176 - * to get the data through the function exactly once, no matter how many
   1.177 - * times the data is given to the function, and no matter the timing of
   1.178 - * trying to get the data through from different cores.
   1.179 - */
   1.180  
   1.181 -/*asm function declarations*/
   1.182 -void asm_save_ret_to_singleton(VSsSingleton *singletonPtrAddr);
   1.183 -void asm_write_ret_from_singleton(VSsSingleton *singletonPtrAddr);
   1.184 -
   1.185 -/*Fn singleton uses ID as index into array of singleton structs held in the
   1.186 - * language environment.
   1.187 - */
   1.188 -void
   1.189 -VSs__start_fn_singleton( int32 singletonID,   SlaveVP *animSlv )
   1.190 - {
   1.191 -   VSsLangReq  reqData;
   1.192 -
   1.193 -      //
   1.194 -   reqData.reqType     = singleton_fn_start;
   1.195 -   reqData.singletonID = singletonID;
   1.196 -
   1.197 -   PR_WL__send_lang_request( &reqData, (RequestHandler)&handleStartFnSingleton,
   1.198 -                             animSlv, VSs_MAGIC_NUMBER );
   1.199 -   if( animSlv->dataRetFromReq ) //will be 0 or addr of label in end singleton
   1.200 -    {
   1.201 -      VSsLangEnv *langEnv =
   1.202 -              PR_int__give_lang_env_for_slave( animSlv, VSs_MAGIC_NUMBER );
   1.203 -      asm_write_ret_from_singleton(&(langEnv->fnSingletons[ singletonID]));
   1.204 -    }
   1.205 - }
   1.206 -
   1.207 -/*Data singleton hands addr of loc holding a pointer to a singleton struct.
   1.208 - * The start_data_singleton makes the structure and puts its addr into the
   1.209 - * location.
   1.210 - */
   1.211 -void
   1.212 -VSs__start_data_singleton( VSsSingleton **singletonAddr,  SlaveVP *animSlv )
   1.213 - {
   1.214 -   VSsLangReq  reqData;
   1.215 -
   1.216 -   if( *singletonAddr && (*singletonAddr)->hasFinished )
   1.217 -       goto JmpToEndSingleton;
   1.218 -   
   1.219 -   reqData.reqType          = singleton_data_start;
   1.220 -   reqData.singletonPtrAddr = singletonAddr;
   1.221 -
   1.222 -   PR_WL__send_lang_request( &reqData, (RequestHandler)&handleStartDataSingleton,
   1.223 -                             animSlv, VSs_MAGIC_NUMBER );
   1.224 -   if( animSlv->dataRetFromReq ) //either 0 or end singleton's return addr
   1.225 -    {    //Assembly code changes the return addr on the stack to the one
   1.226 -         // saved into the singleton by the end-singleton-fn
   1.227 -         //The return addr is at 0x4(%%ebp)
   1.228 -        JmpToEndSingleton:
   1.229 -          asm_write_ret_from_singleton(*singletonAddr);
   1.230 -    }
   1.231 -   //now, simply return
   1.232 -   //will exit either from the start singleton call or the end-singleton call
   1.233 - }
   1.234 -
   1.235 -/*Uses ID as index into array of flags.  If flag already set, resumes from
   1.236 - * end-label.  Else, sets flag and resumes normally.
   1.237 - *
   1.238 - *Note, this call cannot be inlined because the instr addr at the label
   1.239 - * inside is shared by all invocations of a given singleton ID.
   1.240 - */
   1.241 -void
   1.242 -VSs__end_fn_singleton( int32 singletonID, SlaveVP *animSlv )
   1.243 - {
   1.244 -   VSsLangReq  reqData;
   1.245 -
   1.246 -      //don't need this addr until after at least one singleton has reached
   1.247 -      // this function
   1.248 -   VSsLangEnv *
   1.249 -   langEnv = PR_int__give_lang_env_for_slave( animSlv, VSs_MAGIC_NUMBER );
   1.250 -   
   1.251 -   asm_write_ret_from_singleton(&(langEnv->fnSingletons[ singletonID]));
   1.252 -
   1.253 -   reqData.reqType     = singleton_fn_end;
   1.254 -   reqData.singletonID = singletonID;
   1.255 -
   1.256 -   PR_WL__send_lang_request( &reqData, (RequestHandler)&handleEndFnSingleton, 
   1.257 -                             animSlv, VSs_MAGIC_NUMBER );
   1.258 -
   1.259 -EndSingletonInstrAddr:
   1.260 -   return;
   1.261 - }
   1.262 -
   1.263 -void
   1.264 -VSs__end_data_singleton(  VSsSingleton **singletonPtrAddr, SlaveVP *animSlv )
   1.265 - {
   1.266 -   VSsLangReq  reqData;
   1.267 -
   1.268 -      //don't need this addr until after singleton struct has reached
   1.269 -      // this function for first time
   1.270 -      //do assembly that saves the return addr of this fn call into the
   1.271 -      // data singleton -- that data-singleton can only be given to exactly
   1.272 -      // one instance in the code of this function.  However, can use this
   1.273 -      // function in different places for different data-singletons.
   1.274 -   asm_save_ret_to_singleton(*singletonPtrAddr);
   1.275 -
   1.276 -   reqData.reqType          = singleton_data_end;
   1.277 -   reqData.singletonPtrAddr = singletonPtrAddr;
   1.278 -
   1.279 -   PR_WL__send_lang_request( &reqData, (RequestHandler)&handleEndDataSingleton,
   1.280 -                             animSlv, VSs_MAGIC_NUMBER );
   1.281 - }
   1.282 -
   1.283 -/*This executes the function in the masterVP, so it executes in isolation
   1.284 - * from any other copies -- only one copy of the function can ever execute
   1.285 - * at a time.
   1.286 - *
   1.287 - *It suspends to the master, and the request handler takes the function
   1.288 - * pointer out of the request and calls it, then resumes the VP.
   1.289 - *Only very short functions should be called this way -- for longer-running
   1.290 - * isolation, use transaction-start and transaction-end, which run the code
   1.291 - * between as work-code.
   1.292 - */
   1.293 -void
   1.294 -VSs__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
   1.295 -                                    void *data, SlaveVP *animSlv )
   1.296 - {
   1.297 -   VSsLangReq  reqData;
   1.298 -
   1.299 -      //
   1.300 -   reqData.reqType          = atomic;
   1.301 -   reqData.fnToExecInMaster = ptrToFnToExecInMaster;
   1.302 -   reqData.dataForFn        = data;
   1.303 -
   1.304 -   PR_WL__send_lang_request( &reqData, (RequestHandler)&handleAtomic, 
   1.305 -                             animSlv, VSs_MAGIC_NUMBER );
   1.306 - }
   1.307 -
   1.308 -
   1.309 -/*This suspends to the master.
   1.310 - *First, it looks at the VP's data, to see the highest transactionID that VP
   1.311 - * already has entered.  If the current ID is not larger, it throws an
   1.312 - * exception stating a bug in the code.  Otherwise it puts the current ID
   1.313 - * there, and adds the ID to a linked list of IDs entered -- the list is
   1.314 - * used to check that exits are properly ordered.
   1.315 - *Next it is uses transactionID as index into an array of transaction
   1.316 - * structures.
   1.317 - *If the "VP_currently_executing" field is non-null, then put requesting VP
   1.318 - * into queue in the struct.  (At some point a holder will request
   1.319 - * end-transaction, which will take this VP from the queue and resume it.)
   1.320 - *If NULL, then write requesting into the field and resume.
   1.321 - */
   1.322 -void
   1.323 -VSs__start_transaction( int32 transactionID, SlaveVP *animSlv )
   1.324 - {
   1.325 -   VSsLangReq  reqData;
   1.326 -
   1.327 -      //
   1.328 -   reqData.callingSlv  = animSlv;
   1.329 -   reqData.reqType     = trans_start;
   1.330 -   reqData.transID     = transactionID;
   1.331 -
   1.332 -   PR_WL__send_lang_request( &reqData, (RequestHandler)&handleTransStart,
   1.333 -                             animSlv, VSs_MAGIC_NUMBER );
   1.334 - }
   1.335 -
   1.336 -/*This suspends to the master, then uses transactionID as index into an
   1.337 - * array of transaction structures.
   1.338 - *It looks at VP_currently_executing to be sure it's same as requesting VP.
   1.339 - * If different, throws an exception, stating there's a bug in the code.
   1.340 - *Next it looks at the queue in the structure.
   1.341 - *If it's empty, it sets VP_currently_executing field to NULL and resumes.
   1.342 - *If something in, gets it, sets VP_currently_executing to that VP, then
   1.343 - * resumes both.
   1.344 - */
   1.345 -void
   1.346 -VSs__end_transaction( int32 transactionID, SlaveVP *animSlv )
   1.347 - {
   1.348 -   VSsLangReq  reqData;
   1.349 -
   1.350 -      //
   1.351 -   reqData.callingSlv      = animSlv;
   1.352 -   reqData.reqType     = trans_end;
   1.353 -   reqData.transID     = transactionID;
   1.354 -
   1.355 -   PR_WL__send_lang_request( &reqData, (RequestHandler)&handleTransEnd,
   1.356 -                             animSlv, VSs_MAGIC_NUMBER );
   1.357 - }
   1.358 -
   1.359 -//======================== Internal ==================================
   1.360 -