# HG changeset patch # User Me # Date 1275341018 25200 # Node ID 02d5a446d506a2ec6dc065fac767e61456d29a5b # Parent cf5007e51b96e04a5718b50ef61e9dde0b3567ee Compiles with assembly -- warning about jmp w/o '*'? diff -r cf5007e51b96 -r 02d5a446d506 CoreLoop.c --- a/CoreLoop.c Mon May 31 14:11:14 2010 -0700 +++ b/CoreLoop.c Mon May 31 14:23:38 2010 -0700 @@ -5,9 +5,6 @@ */ - - - #include "VMS.h" #include "Queue_impl/BlockingQueue.h" @@ -22,41 +19,46 @@ * write the slave's "Done" flag and repeat. */ //pthread_create requires ptr to func that takes void * and returns void * -void * coreLoop( void *paramsIn ) - { time_t startTime, endTime, timeToExecute; - WorkUnit *currWorkUnit; - foobar *workFn; - SlaveReqst *requestsFromSlave; - - ThdParams *thdParams; - QueueStruc *workQ; +void * +coreLoop( void *paramsIn ) + { + ThdParams *thdParams; + VirtProcr *currPr; + QueueStruc *workQ; // Get the communication queues out of the param passed in thdParams = (ThdParams *)paramsIn; + + //Core loop has no values live upon CoreLoopStartPt except workQ + // every value in the code is defined by a statement in core loop, + // after the start point, before being used -- with the one exception + // of _VMSWorkQ + - workQ = thdParams -> workQ; + // Get to work! -- virt procr jumps back here when done or suspends + CoreLoopStartPt: - // Get to work! - while( TRUE ) - { - // get work-unit struc from queue - currWorkUnit = (WorkUnit *) readQ( workQ ); - workFn = currWorkUnit->ptrToWorkFunc; + //Get virtual processor from queue + //_VMSWorkQ must be a global, static volatile var, so not kept in reg, + // which forces reloading the pointer after each jmp to this point + workQ = _VMSWorkQ; + currPr = (VirtProcr *) readQ( workQ ); + currPr->coreLoopStartPt = &&CoreLoopStartPt; //just to be sure.. - time(&startTime); //put time at call into var - - // call function-ptr, passing it pointer to data - requestsFromSlave = - (*workFn)( currWorkUnit->workData ); - - time(&endTime); - timeToExecute = endTime - startTime; - - printf( "timeToComputePiece: %s", ctime(&timeToExecute) ); - - // transfer return value to slave's "requests" pointer - currWorkUnit->slaveAssignedTo->requestsToMaster = requestsFromSlave; - // write the slave's "Done" flag and repeat. - currWorkUnit->slaveAssignedTo->doneFlag = TRUE; - } + //switch to virt procr's stack and frame ptr then jump to virt procr + void *stackPtr, *framePtr, *jmpPt; + + stackPtr = currPr->stackPtr; + framePtr = currPr->framePtr; + jmpPt = currPr->nextInstrPt; + + __asm__ volatile("movl %0, %%esp; movl %1, %%ebp; jmp %2" + /* outputs */ : + /* inputs */ : "g" (stackPtr), "g" (framePtr), "g" (jmpPt) + /* clobber */ : "memory" /*just in case, Q: tell about esp, ebp?*/ + ); } + //Note: will only exit this when application dies -- so core loop's stack + // can be safely ignored -- it's a user-process virtual chunk allocated + // by PThread lib call that created the thread.. so no cleanup is needed.. + // it's never used anywhere, except upon startup of the thread