| Tekkotsu Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
ProcessID.ccGo to the documentation of this file.00001 #include "ProcessID.h" 00002 00003 #include "Shared/WorldState.h" 00004 00005 #ifdef PLATFORM_APERIOS 00006 # include <iostream> 00007 using namespace stacktrace; 00008 #endif 00009 00010 using namespace std; 00011 00012 namespace ProcessID { 00013 ProcessID_t ID=NumProcesses; //!< holds ID number 00014 00015 #ifndef PLATFORM_APERIOS 00016 // on "normal" platforms we can trust the id specified by the process to stay consistent 00017 ProcessID_t getID() { return ID; } 00018 00019 #else 00020 // but on the Aibo, we have to unroll the stack to see which thread it is 00021 00022 //! array of StackFrame structures, one per #NumProcesses, set by setMap() 00023 StackFrame* frames=NULL; 00024 00025 //! 00026 void setMap(stacktrace::StackFrame idmap[]) { 00027 frames=idmap; 00028 } 00029 00030 stacktrace::StackFrame* getMapFrame() { 00031 if(frames==NULL) //setMap hasn't been called yet 00032 return NULL; 00033 if(ID==NumProcesses) // ID hasn't been set 00034 return NULL; 00035 return &frames[ID]; 00036 } 00037 00038 00039 ProcessID_t getID() { 00040 if(frames==NULL) { //setMap hasn't been called yet 00041 //cerr << "getID() called before setMap() id==" << ID << endl; 00042 //displayCurrentStackTrace(); 00043 return ID; 00044 } 00045 StackFrame f; 00046 #ifdef DEBUG_STACKTRACE 00047 f.debug=(state!=NULL)?(state->buttons[LFrPawOffset]>.1):1; 00048 if(f.debug) 00049 fprintf(stderr,"getID() for %d: ",ID); 00050 #endif 00051 getCurrentStackFrame(&f); 00052 while(unrollStackFrame(&f,&f)) {} 00053 for(unsigned int i=0; i<NumProcesses; i++) { 00054 if(frames[i].gp==f.gp) { 00055 #ifdef DEBUG_STACKTRACE 00056 if(i!=(unsigned int)ID || f.debug) 00057 cout << "getID() from " << ID << " is " << i << endl; 00058 #endif 00059 return static_cast<ProcessID_t>(i); 00060 } 00061 } 00062 cerr << "ERROR: Unknown entry point (sp=" << f.sp << ",ra=" << (void*)f.ra << ",gp=" << (void*)f.gp << "), implied process " << ID << endl; 00063 displayCurrentStackTrace(); 00064 cerr << "Map:" << endl; 00065 for(unsigned int i=0; i<NumProcesses; i++) 00066 cerr << " " << i << " (sp=" << frames[i].sp << ",ra=" << (void*)frames[i].ra << ",gp=" << (void*)frames[i].gp << ")" << endl; 00067 return ID; 00068 } 00069 00070 #endif 00071 00072 void setID(ProcessID_t id) { ID=id; } 00073 } 00074 00075 00076 00077 /*! @file 00078 * @brief Declares the static ProcessID::ID, that's all 00079 * @author ejt (Creator) 00080 * 00081 * $Author: ejt $ 00082 * $Name: tekkotsu-3_0 $ 00083 * $Revision: 1.6 $ 00084 * $State: Exp $ 00085 * $Date: 2006/09/16 06:01:40 $ 00086 */ 00087 |
|
Tekkotsu v3.0 |
Generated Wed Oct 4 00:03:45 2006 by Doxygen 1.4.7 |