00001 // Filename: pStatThread.I 00002 // Created by: drose (11Jul00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: PStatThread::Default Constructor 00018 // Access: Private 00019 // Description: Normally, this constructor is called only from 00020 // PStatClient. Use one of the constructors below to 00021 // create your own Thread. 00022 //////////////////////////////////////////////////////////////////// 00023 INLINE PStatThread:: 00024 PStatThread() { 00025 } 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Function: PStatThread::Constructor 00029 // Access: Private 00030 // Description: Normally, this constructor is called only from 00031 // PStatClient. Use one of the constructors below to 00032 // create your own Thread. 00033 //////////////////////////////////////////////////////////////////// 00034 INLINE PStatThread:: 00035 PStatThread(PStatClient *client, int index) : 00036 _client(client), 00037 _index(index) 00038 { 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: PStatThread::Constructor 00043 // Access: Public 00044 // Description: Creates a new named thread. This will be used to 00045 // unify tasks that share a common thread, and 00046 // differentiate tasks that occur in different threads. 00047 //////////////////////////////////////////////////////////////////// 00048 INLINE PStatThread:: 00049 PStatThread(Thread *thread, PStatClient *client) { 00050 #ifdef DO_PSTATS 00051 if (client == (PStatClient *)NULL) { 00052 client = PStatClient::get_global_pstats(); 00053 } 00054 00055 int thread_index = thread->get_pstats_index(); 00056 if (thread_index != -1) { 00057 (*this) = PStatThread(client, thread_index); 00058 00059 } else { 00060 // This is the first time we have encountered this current Thread. 00061 // Make a new PStatThread object for it. 00062 (*this) = client->make_thread(thread); 00063 } 00064 #else 00065 _client = (PStatClient *)NULL; 00066 _index = 0; 00067 #endif 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: PStatThread::Copy Constructor 00072 // Access: Public 00073 // Description: 00074 //////////////////////////////////////////////////////////////////// 00075 INLINE PStatThread:: 00076 PStatThread(const PStatThread ©) : 00077 _client(copy._client), 00078 _index(copy._index) 00079 { 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: PStatThread::Copy Assignment Operator 00084 // Access: Public 00085 // Description: 00086 //////////////////////////////////////////////////////////////////// 00087 INLINE void PStatThread:: 00088 operator = (const PStatThread ©) { 00089 _client = copy._client; 00090 _index = copy._index; 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: PStatThread::new_frame 00095 // Access: Public 00096 // Description: This must be called at the start of every "frame", 00097 // whatever a frame may be deemed to be, to accumulate 00098 // all the stats that have collected so far for the 00099 // thread and ship them off to the server. 00100 // 00101 // Calling PStatClient::thread_tick() will automatically 00102 // call this for any threads with the indicated sync 00103 // name. 00104 //////////////////////////////////////////////////////////////////// 00105 INLINE void PStatThread:: 00106 new_frame() { 00107 #ifdef DO_PSTATS 00108 _client->get_impl()->new_frame(_index); 00109 #endif 00110 } 00111 00112 //////////////////////////////////////////////////////////////////// 00113 // Function: PStatThread::get_index 00114 // Access: Published 00115 // Description: Returns the index number of this particular thread 00116 // within the PStatClient. 00117 //////////////////////////////////////////////////////////////////// 00118 INLINE int PStatThread:: 00119 get_index() const { 00120 return _index; 00121 }