Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

SharedGlobals.cc

Go to the documentation of this file.
00001 #include "SharedGlobals.h"
00002 #include "Simulator.h"
00003 
00004 const char * const SharedGlobals::runlevel_names[SharedGlobals::NUM_RUNLEVELS+1] = {
00005   "CREATED",
00006   "CONSTRUCTING",
00007   "STARTING",
00008   "RUNNING",
00009   "STOPPING",
00010   "DESTRUCTING",
00011   "DESTRUCTED",
00012   NULL
00013 };
00014 
00015 ipc_setup_t * ipc_setup=NULL;
00016 SharedGlobals * globals=NULL;
00017 
00018 unsigned int SharedGlobals::get_time() {
00019   decltype(lastTimeScale) lastLastTimeScale=lastTimeScale; // used to avoid repeated "pause" commands if we're past autoPauseTime
00020   if(timeScale<=0) {
00021     //just need to update lastTimeScale in case it had been realtime mode
00022     //adding an 'if' to test before the assignment is slower than just always doing the assignment
00023     lastTimeScale=timeScale;
00024   } else {
00025     if(lastTimeScale<=0) {
00026       //switching from non-realtime to realtime mode -- reset time offset
00027       timeOffset=bootTime.Age().Value()*timeScale*1000-simulatorTime;
00028       lastTimeScale=timeScale;
00029       //we reset timeOffset such that simulatorTime hasn't changed
00030     } else if(lastTimeScale!=timeScale) {
00031       //switching speeds -- reset time offset
00032       simulatorTime=get_real_time(lastTimeScale);
00033       timeOffset=bootTime.Age().Value()*timeScale*1000-simulatorTime;
00034       lastTimeScale=timeScale;
00035     } else {
00036       simulatorTime=get_real_time(timeScale);
00037     }
00038     //cout << timeOffset << ' ' << lastTimeScale << ' ' << timeScale << endl;
00039   }
00040   if(simulatorTime>autoPauseTime) {
00041     simulatorTime=autoPauseTime;
00042     if(ProcessID::getID()==ProcessID::SimulatorProcess) {
00043       if(timeScale!=0) // don't reset it if it's already set -- triggers infinite recursion if/when the hook calls get_time
00044         timeScale=0;
00045     } else {
00046       // can't set timeScale directly because Simulator process has hooks registered and we aren't in the Simulator process
00047       if(lastLastTimeScale!=0) {
00048         lastTimeScale=0;
00049         Simulator::sendCommand("pause quiet"); // so do this instead
00050       }
00051     }
00052   }
00053   return simulatorTime;
00054 }
00055 
00056 float SharedGlobals::getTimeScale() const { return (float)timeScale; }
00057 
00058 /*! @file
00059  * @brief A class to hold various simulator parameters which need to be accessed from multiple processes
00060  * @author ejt (Creator)
00061  */

Tekkotsu Hardware Abstraction Layer 5.1CVS
Generated Mon May 9 05:01:39 2016 by Doxygen 1.6.3