VMS/VMS_Implementations/VMS_impls/VMS__MC_shared_impl

view AnimationMaster.c @ 290:c63b498d0a00

Fixed post-merge issues -- renames and includes..
author Sean Halle <seanhalle@yahoo.com>
date Thu, 05 Sep 2013 18:49:48 -0700
parents 744b5ff9851e
children
line source
1 /*
2 * Copyright 2012 OpenSourceResearchInstitute.org
3 *
4 * Licensed under BSD
5 */
9 #include <stdio.h>
10 #include <stddef.h>
12 #include "PR.h"
14 //========================= Local Declarations ========================
15 inline PRProcess *
16 pickAProcess( AnimSlot *slot );
17 inline bool32
18 assignWork( PRProcess *process, AnimSlot *slot );
20 inline void
21 PRHandle__CreateTask( PRReqst *req, SlaveVP *slave );
22 inline void
23 PRHandle__EndTask( PRReqst *req, SlaveVP *slave );
24 inline void
25 PRHandle__CreateSlave(PRReqst *req, SlaveVP *slave );
26 inline void
27 PRHandle__EndSlave( PRReqst *req, SlaveVP *slave );
29 inline void
30 PRHandle__LangShutdown( PRReqst *req, SlaveVP *requestingSlv );
32 inline void
33 handleMakeProbe( PRServiceReq *langReq, PRLangEnv *protoLangEnv );
34 inline void
35 handleThrowException( PRServiceReq *langReq, PRLangEnv *protoLangEnv );
37 void
38 debug_print_req(AnimSlot *slot, PRReqst *req);
40 //===========================================================================
42 /*Note: there used to be a coreController that was another animation
43 * layer below both the masterVP and the slaveVPs.. in that case, the
44 * masterVP was a virtual processor whose processor-state was the same
45 * as a slaveVP's processor sate, both implemented as a SlaveVP struct.
46 * Have removed that, and
47 * changed the masterVP implementation. Instead of being a special version
48 * of a proto-runtime virtual processor, using the slaveVP stuct, the
49 * Master "virtual processor" is now implemented as a pthread pinned to
50 * a physical core.
51 */
53 /*This is the behavior of the Master. The physical processor switches
54 * between animating the master, and animating a slave. When a slave
55 * suspends, the PR "suspend" primitive switches the physical core over
56 * to animating the masterVP, which is implemented as a pinned pthread.
57 * This function is the behavior of that masterVP.
58 *This function's job is to manage processing
59 * requests and to trigger assignment of new work to the physical core,
60 * and to manage sharing the core among processes.
61 */
62 inline
63 bool32
64 masterFunction( AnimSlot *slot )
65 { //Scan the animation slots
66 int32 magicNumber;
67 SlaveVP *slave;
68 PRLangEnv *langEnv;
69 PRReqst *req;
70 PRProcess *process;
71 bool32 didAssignWork;
73 //Check if newly-done slave in slot, which will need request handled
74 //NOTE: left over from when had a coreController & MasterVP managed
75 // several slots
76 if( slot->workIsDone )
77 { slot->workIsDone = FALSE;
78 slot->needsWorkAssigned = TRUE;
80 //An Idle VP has no request to handle, so skip to assign..
81 if( slot->slaveAssignedToSlot->typeOfVP != IdleVP &&
82 slot->slaveAssignedToSlot->typeOfVP != ShutdownVP)
83 {
84 HOLISTIC__Record_AppResponder_start; //TODO: update to check which process for each slot
85 MEAS__startReqHdlr;
88 //process the request made by the slave (held inside slave struc)
89 slave = slot->slaveAssignedToSlot;
90 req = slave->request;
92 //If the requesting slave is a slot slave, and request is not
93 // task-end, then turn it into a free task slave & continue
94 if( slave->typeOfVP == SlotTaskSlv && req->reqType != TaskEnd )
95 PR_int__replace_with_new_slot_slv( slave );
97 //Handle task create and end first -- they're special cases..
98 switch( req->reqType )
99 {
100 case TaskEnd:
101 { //do PR handler, which calls lang's hdlr and does recycle of
102 // free task slave if needed -- PR handler checks for free task Slv
103 PRHandle__EndTask( req, slave ); break;
104 }
105 case TaskCreate:
106 { //Do PR's create-task handler, which calls the lang's hdlr
107 // PR handler checks for free task Slv
108 PRHandle__CreateTask( req, slave ); break;
109 }
110 case SlvCreate: PRHandle__CreateSlave( req, slave ); break;
111 case SlvDissipate: PRHandle__EndSlave( req, slave ); break;
112 case Service: PRHandle__ServiceReq( slave ); break; //resumes into Service lang env
113 case Hardware: //for future expansion
114 case IO: //for future expansion
115 case OSCall: //for future expansion
116 PR_int__throw_exception("Not implemented", slave, NULL); break;
117 case LangShutdown: PRHandle__LangShutdown( req, slave ); break;
118 case Language: //normal lang request
119 { magicNumber = req->langMagicNumber;
120 langEnv = PR_PI__give_lang_env_for_slave( slave, magicNumber );
121 (*req->handler)( req->langReq, slave, langEnv );
122 }
123 }
125 MEAS__endReqHdlr;
126 HOLISTIC__Record_AppResponder_end;
127 }//if not idleVP
128 else if( slot->slaveAssignedToSlot->typeOfVP == ShutdownVP )
129 { //ShutdownVP used, essentially, as a flag, to cause terminate here
130 PR_int__release_master_lock();
131 terminateCoreCtlr( slot->slaveAssignedToSlot );
132 }
133 } //if have request to be handled
135 //NOTE: IF statement is leftover from when master managed many slots
136 didAssignWork = FALSE;
137 if( slot->needsWorkAssigned ) //can probably remove IF, now that only one slot
138 {
139 HOLISTIC__Record_Assigner_start;
141 //Pick a process to get this slot
142 process = pickAProcess( slot );
144 //Scan lang environs, looking for langEnv with ready work.
145 // call the Assigner for that lang Env, to get a slave for the slot
146 if( process != NULL )
147 { didAssignWork =
148 assignWork( process, slot );
149 }
150 HOLISTIC__Record_Assigner_end;
152 if( !didAssignWork ) //if no work assigned, be sure idle slave is in slot
153 { slot->slaveAssignedToSlot = _PRTopEnv->idleSlv[slot->coreSlotIsOn][0];
154 }
155 // fixme; //make into a loop that tries more processes if fails to assign
156 }//if slot needs slave assigned
158 return didAssignWork;
159 }
161 /*When several processes exist, use some pattern for picking one to give
162 * the animation slot to.
163 *First, it has to be a process that has work available.
164 *For now, just do a round-robin
165 */
166 inline
167 PRProcess *
168 pickAProcess( AnimSlot *slot )
169 { int32 idx;
170 PRProcess *process;
172 for( idx = _PRTopEnv->currProcessIdx; idx < _PRTopEnv->numProcesses; idx++)
173 {
174 process = _PRTopEnv->processes[ idx ];
175 if( process->numEnvsWithWork != 0 )
176 { _PRTopEnv->currProcessIdx = idx;
177 return process;
178 }
179 }
180 for( idx = 0; idx < _PRTopEnv->currProcessIdx; idx++)
181 {
182 process = _PRTopEnv->processes[ idx ];
183 if( process->numEnvsWithWork != 0 )
184 { _PRTopEnv->currProcessIdx = idx;
185 return process;
186 }
187 }
188 //none found
189 return NULL;
190 }
192 /*This does:
193 * 1) searches the language environments for one with work ready
194 * if finds one, asks its assigner to return work
195 * 2) checks what kind of work: new task, resuming task, resuming slave
196 * if new task, gets the slot slave and assigns task to it and returns slave
197 * else, gets the slave attached to the metaTask and returns that.
198 * 3) if no work found, then prune former task slaves waiting to be recycled.
199 * If no work and no slaves to prune, check for shutdown conditions.
200 *
201 * language env keeps its own work in its own structures, and has its own
202 * assigner. It chooses
203 * However, include a switch that switches-in an override assigner, which
204 * sees all the work in all the language env's. This is most likely
205 * generated by static tools and included in the executable. That means it
206 * has to be called via a registered pointer from here. The idea is that
207 * the static tools know which languages are grouped together.. and the
208 * override enables them to generate a custom assigner that uses info from
209 * all the languages in a unified way.. Don't really expect this to happen,
210 * but am making it possible.
211 */
212 inline
213 bool32
214 assignWork( PRProcess *process, AnimSlot *slot )
215 { int32 coreNum;
217 coreNum = slot->coreSlotIsOn;
219 if( process->overrideAssigner != NULL )
220 { if( process->numEnvsWithWork != 0 )
221 { (*process->overrideAssigner)( process, slot ); //calls PR fn that inserts work into slot
222 goto ReturnAfterAssigningWork; //quit for-loop, cause found work
223 }
224 else
225 goto NoWork;
226 }
228 //If here, then no override assigner, so search language envs for work
229 int32 envIdx, numEnvs; PRLangEnv **protoLangEnvsList, *protoLangEnv;
230 protoLangEnvsList = process->protoLangEnvsList;
231 numEnvs = process->numLangEnvs;
232 for( envIdx = 0; envIdx < numEnvs; envIdx++ ) //keep langEnvs in hash & array
233 { protoLangEnv = protoLangEnvsList[envIdx];
234 if( protoLangEnv->numReadyWork > 0 )
235 { bool32
236 didAssignWork =
237 (*protoLangEnv->workAssigner)( PR_int__give_lang_env(protoLangEnv), slot ); //assigner calls PR to put slave/task into slot
239 if(didAssignWork)
240 { protoLangEnv->numReadyWork -= 1;
241 if( protoLangEnv->numReadyWork == 0 )
242 { process->numEnvsWithWork -= 1;
243 }
244 goto ReturnAfterAssigningWork; //quit for-loop, 'cause found work
245 }
246 else
247 goto NoWork; //quit for-loop, cause found work
249 //NOTE: bad search alg -- should start where left off, then wrap around
250 }
251 }
252 //If reach here, then have searched all langEnv's & none have work..
254 NoWork: //No work, if end up here..
255 {
256 #ifdef HOLISTIC__TURN_ON_OBSERVE_UCC
257 returnSlv = process->idleSlv[coreNum][0]; //only one slot now, so [0]
259 //things that would normally happen in resume(), but idle VPs
260 // never go there
261 returnSlv->numTimesAssignedToASlot++; //gives each idle unit a unique ID
262 Unit newU;
263 newU.vp = returnSlv->slaveNum;
264 newU.task = returnSlv->numTimesAssignedToASlot;
265 addToListOfArrays(Unit,newU,process->unitList);
267 if (returnSlv->numTimesAssignedToASlot > 1) //make a dependency from prev idle unit
268 { Dependency newD; // to this one
269 newD.from_vp = returnSlv->slaveNum;
270 newD.from_task = returnSlv->numTimesAssignedToASlot - 1;
271 newD.to_vp = returnSlv->slaveNum;
272 newD.to_task = returnSlv->numTimesAssignedToASlot;
273 addToListOfArrays(Dependency, newD ,process->ctlDependenciesList);
274 }
275 #endif
276 HOLISTIC__Record_Assigner_end;
277 return FALSE;
278 }
280 ReturnAfterAssigningWork: //All paths goto here.. to provide single point for holistic..
281 {
282 HOLISTIC__Record_Assigner_end;
283 return TRUE;
284 }
285 }
288 //=================================
289 //===
290 //=
291 /*Create task is a special form, that has PR behavior in addition to plugin
292 * behavior. Master calls this first, and it then calls the plugin's
293 * create task handler.
294 *
295 *Note: the requesting slave must be either generic slave or free task slave
296 */
297 inline
298 void
299 PRHandle__CreateTask( PRReqst *req, SlaveVP *slave )
300 { PRMetaTask *protoMetaTask;
301 PRProcess *process;
302 PRLangEnv *protoLangEnv;
303 void *task;
305 process = slave->processSlaveIsIn;
307 protoLangEnv = PR_int__give_proto_lang_env_for_slave( slave,
308 req->langMagicNumber );
310 //Do the langlet's create-task handler, which keeps the task
311 // inside the langlet's lang env, but returns the langMetaTask
312 // so that PR can then put stuff into the prolog
313 //typedef void * (*CreateHandler)( void *, SlaveVP *, void * ); //req, slv, langEnv
314 //
315 task =
316 (*req->createHdlr)(req->langReq, slave, PR_int__give_lang_env(protoLangEnv) );
317 protoMetaTask = PR_int__give_prolog_of_lang_meta_task( task );
318 protoMetaTask->ID = req->ID; //may be NULL
319 protoMetaTask->topLevelFn = req->birthFnPtr;
320 protoMetaTask->initData = req->initData;
321 protoMetaTask->processTaskIsIn = process;
323 process->numLiveTasks += 1;
324 protoLangEnv->numLiveWork += 1; //used in wait statements -- small added overhead
326 return;
327 }
329 /*When a task ends, have two scenarios: 1) task ran to completion, or 2) task
330 * has been suspended at some point in its code.
331 *For 1, just decr count of live tasks (and check for end condition) -- the
332 * master loop will decide what goes into the slot freed up by this task end,
333 * so, here, don't worry about assigning a new task to the slot slave.
334 *For 2, the task's slot slave has been converted to a free task slave, which
335 * now has nothing more to do, so send it to the recycle Q (which includes
336 * freeing all the langData and meta task structs alloc'd for it). Then
337 * decrement the live task count and check end condition.
338 *
339 *PR has to update count of live tasks, and check end of process condition.
340 * The "main" can invoke constructs that wait for a process to end, so when
341 * end detected, have to resume what's waiting..
342 *Thing is, that wait involves the main OS thread. That means
343 * PR internals have to do OS thread signaling. Want to do that in the
344 * core controller, which has the original stack of an OS thread. So the
345 * end process handling happens in the core controller.
346 *
347 *So here, when detect process end, signal to the core controller, which will
348 * then do the condition variable notify to the OS thread that's waiting.
349 *
350 *Note: slave may be either a slot slave or a free task slave.
351 */
352 inline
353 void
354 PRHandle__EndTask( PRReqst *req, SlaveVP *requestingSlv )
355 { void *langEnv;
356 PRLangEnv *protoLangEnv;
357 PRProcess *process;
358 void *langMetaTask;
360 process = requestingSlv->processSlaveIsIn;
361 langEnv = PR_int__give_lang_env_of_req( req, requestingSlv ); //magic num in req
362 protoLangEnv = PR_int__give_proto_lang_env( langEnv );
364 langMetaTask = PR_int__give_lang_meta_task_from_slave( requestingSlv, req->langMagicNumber);
366 //Do the langlet's request handler
367 //Want to keep PR structs hidden from plugin, so extract langReq..
368 //This is supposed to free any langlet-malloc'd mem, including meta task
369 (*req->handler)( req->langReq, requestingSlv, langEnv );
371 protoLangEnv->numLiveWork -= 1; //used in wait statements -- small added overhead
372 if( protoLangEnv->numLiveWork == 0 &&
373 numInPrivQ( protoLangEnv->waitingForWorkToEndQ ) > 0 )
374 { SlaveVP *
375 waitingSlave = readPrivQ( protoLangEnv->waitingForWorkToEndQ );
376 //can't resume into langlet that just ended its last work!
377 // and don't have env that the waiter was created in, so resume
378 // into PRServ env..
379 void *
380 resumeEnv = PR_PI__give_lang_env_from_process( process, PRServ_MAGIC_NUMBER );
381 while( waitingSlave != NULL )
382 { //resume a slave that was waiting for work in this env to finish
383 PR_PI__make_slave_ready( waitingSlave, resumeEnv );
384 //get next waiting slave, repeat..
385 waitingSlave = readPrivQ( protoLangEnv->waitingForWorkToEndQ );
386 }
387 }
390 //Now that the langlet's done with it, recycle the slave if it's a freeTaskSlv
391 if( requestingSlv->typeOfVP == FreeTaskSlv )
392 PR_int__recycle_slaveVP( requestingSlv ); //Doesn't decr num live slaves
394 process->numLiveTasks -= 1;
395 //NOTE: end-task is unrelated to work available (just in case wondering)
397 //check End Of Process Condition
398 if( process->numLiveTasks == 0 &&
399 process->numLiveGenericSlvs == 0 )
400 { //Tell the core controller to do wakeup of any waiting OS thread
401 PR_SS__end_process_normally( process );
402 }
403 }
407 /*This is first thing called when creating a slave.. it hands off to the
408 * langlet's creator, then adds updates of its own..
409 *
410 *There's a question of things like lang data, meta tasks, and such..
411 *In creator, only PR related things happen, and things for the langlet whose
412 * creator construct was used.
413 *
414 *Other langlets still get a chance to create langData -- but by registering a
415 * "createLangData" handler in the langEnv. When a construct of the langlet
416 * calls "PR__give_lang_data()", if there is no langData for that langlet,
417 * the PR will call the creator in the langlet's langEnv, place whatever it
418 * makes as the langData in that slave for that langlet, and return that langData
419 *
420 *So, as far as counting things, a langlet is only allowed to count creation
421 * of slaves it creates itself.. may have to change this later.. add a way for
422 * langlet to register a trigger Fn called each time a slave gets created..
423 * need more experience with what langlets will do at create time.. think Cilk
424 * has interesting create behavior.. not sure how that will differ in light
425 * of true tasks and langlet approach. Look at it after all done and start
426 * modifying the langs to be langlets..
427 *
428 *PR itself needs to create the slave, then update numLiveSlaves in process,
429 * copy processID from requestor to newly created
430 */
431 inline
432 void
433 PRHandle__CreateSlave( PRReqst *req, SlaveVP *slave )
434 { SlaveVP *newSlv;
435 PRProcess *process;
436 PRLangEnv *protoLangEnv;
438 process = slave->processSlaveIsIn;
439 protoLangEnv = PR_int__give_proto_lang_env_for_slave( slave, req->langMagicNumber );
441 //create handler, or a future request handler will call PR_PI__make_slave_ready
442 // which will in turn handle updating which langlets and which processes have
443 // work available.
444 //NOTE: create slv has diff prototype than standard reqst hdlr
445 newSlv =
446 (*req->createHdlr)(req->langReq, slave, PR_int__give_lang_env(protoLangEnv));
448 newSlv->typeOfVP = GenericSlv;
449 newSlv->processSlaveIsIn = process;
450 newSlv->ID = req->ID;
451 process->numLiveGenericSlvs += 1; //not same as work ready!
452 protoLangEnv->numLiveWork += 1; //used in wait statements -- small added overhead
453 }
455 /*The dissipate handler has to, update the number of slaves of the type, within
456 * the process, and call the langlet handler linked into the request,
457 * and after that returns, then call the PR function that frees the slave state
458 * (or recycles the slave).
459 *
460 *The PR function that frees the slave state has to also free all of the
461 * langData in the slave.. or else reset all of the langDatas.. by, say, marking
462 * them, then in PR__give_langData( magicNum ) call the langlet registered
463 * "resetLangData" Fn.
464 */
465 inline
466 void
467 PRHandle__EndSlave( PRReqst *req, SlaveVP *slave )
468 { PRProcess *process;
469 PRLangEnv *protoLangEnv;
471 process = slave->processSlaveIsIn;
473 //do the language's dissipate handler
474 protoLangEnv = PR_int__give_proto_lang_env_for_slave( slave, slave->request->langMagicNumber );
476 if(req->handler != NULL)
477 (*req->handler)( req->langReq, slave, PR_int__give_lang_env(protoLangEnv) );
479 protoLangEnv->numLiveWork -= 1; //used in wait statements -- small added overhead
480 if( protoLangEnv->numLiveWork == 0 &&
481 numInPrivQ( protoLangEnv->waitingForWorkToEndQ ) > 0 )
482 { SlaveVP *
483 waitingSlave = readPrivQ( protoLangEnv->waitingForWorkToEndQ );
484 //can't resume into langlet that just ended its last work!
485 // and don't have env that the waiter was created in, so resume
486 // into PRServ env..
487 void *
488 resumeEnv = PR_PI__give_lang_env_from_process( process, PRServ_MAGIC_NUMBER );
489 while( waitingSlave != NULL )
490 { //resume a slave that was waiting for work in this env to finish
491 PR_PI__make_slave_ready( waitingSlave, resumeEnv );
492 //get next waiting slave, repeat..
493 waitingSlave = readPrivQ( protoLangEnv->waitingForWorkToEndQ );
494 }
495 }
497 process->numLiveGenericSlvs -= 1;
498 PR_int__recycle_slaveVP( slave );
499 //NOTE: dissipate is unrelated to work available (just in case wondering)
501 //check End Of Process Condition
502 if( process->numLiveTasks == 0 &&
503 process->numLiveGenericSlvs == 0 )
504 PR_SS__end_process_normally( process );
505 }
507 //=======================
508 //===
509 //=
510 /*Langlet shutdown triggers this, which calls the registered shutdown
511 * handler for the langlet, and removes the lang's env from the process
512 */
513 inline
514 void
515 PRHandle__LangShutdown( PRReqst *req, SlaveVP *requestingSlv )
516 { void *langEnv;
517 PRLangEnv *protoLangEnv;
518 PRProcess *process;
520 process = requestingSlv->processSlaveIsIn;
521 protoLangEnv = PR_int__give_proto_lang_env_from_process( process, req->langMagicNumber );
522 langEnv = PR_int__give_lang_env( protoLangEnv );
524 //call the langlet's registered handler
525 (*protoLangEnv->shutdownHdlr)( langEnv );
527 PR_int__remove_lang_env_from_process_and_free( langEnv ); //removes from process and frees
529 PR_PI__resume_slave_in_PRServ( requestingSlv );
530 }
533 /*This is for OS requests and PR infrastructure requests, which are not
534 * part of the PRServ language -- this is for things that have to be in the
535 * infrastructure of PR itself, such as I/O requests, which have to go through
536 * pthreads inside the core controller..
537 *
538 *As of Jan 2013, doesn't do much of anything..
539 */
540 void inline
541 PRHandle__ServiceReq( SlaveVP *requestingSlv )
542 { PRReqst *req;
543 PRServiceReq *langReq;
544 PRLangEnv *protoLangEnv;
545 int32 magicNumber;
548 req = requestingSlv->request;
550 magicNumber = req->langMagicNumber;
551 protoLangEnv = PR_int__give_proto_lang_env_for_slave( requestingSlv, magicNumber );
553 langReq = PR_PI__take_lang_reqst_from(req);
554 if( langReq == NULL ) return;
555 switch( langReq->reqType ) //lang handlers are all in other file
556 {
557 case make_probe: handleMakeProbe( langReq, protoLangEnv );
558 break;
559 case throw_excp: handleThrowException( langReq, protoLangEnv );
560 break;
561 }
562 }
565 /*These handlers are special -- they don't belong to a language, because they
566 * deal with things internal to PR, so put them here..
567 */
568 inline
569 void
570 handleMakeProbe( PRServiceReq *langReq, PRLangEnv *protoLangEnv )
571 { IntervalProbe *newProbe;
573 newProbe = PR_int__malloc( sizeof(IntervalProbe) );
574 newProbe->nameStr = PR_int__strDup( langReq->nameStr );
575 newProbe->hist = NULL;
576 newProbe->schedChoiceWasRecorded = FALSE;
578 //This runs in masterVP, so no race-condition worries
579 //BUG: move to process
580 newProbe->probeID =
581 addToDynArray( newProbe, _PRTopEnv->dynIntervalProbesInfo );
583 langReq->requestingSlv->dataRetFromReq = newProbe;
585 (*protoLangEnv->makeSlaveReadyFn)( langReq->requestingSlv, PR_int__give_lang_env(protoLangEnv) );
586 }
588 inline
589 void
590 handleThrowException( PRServiceReq *langReq, PRLangEnv *protoLangEnv )
591 {
592 PR_int__throw_exception( langReq->msgStr, langReq->requestingSlv, langReq->exceptionData );
594 (*protoLangEnv->makeSlaveReadyFn)( langReq->requestingSlv, PR_int__give_lang_env(protoLangEnv) );
595 }
597 void
598 debug_print_req(AnimSlot *slot, PRReqst *req)
599 {
600 if(dbgMaster)
601 { printf("top handle request: %d | reqType: ", slot->coreSlotIsOn );
602 switch(req->reqType)
603 { case TaskCreate: printf("TaskCreate \n"); break;
604 case TaskEnd: printf("TaskEnd \n"); break;
605 case SlvCreate: printf("SlvCreate \n"); break;
606 case SlvDissipate: printf("SlvDissipate \n"); break;
607 case Language: printf("Language \n"); break;
608 case Service: printf("Service \n"); break;
609 case Hardware: printf("Hardware \n"); break;
610 case IO: printf("IO \n"); break;
611 case OSCall: printf("OSCall \n"); break;
612 case LangShutdown: printf("LangShutdown \n"); break;
613 case ProcessEnd: printf("ProcessEnd \n"); break;
614 case PRShutdown: printf("PRShutdown \n"); break;
615 }
616 fflush(stdin);
617 }
618 }