Panda3D
|
00001 // Filename: cycleDataLockedStageReader.I 00002 // Created by: drose (30Apr06) 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 #ifndef CPPPARSER 00016 00017 #ifdef DO_PIPELINING 00018 // This is the implementation for full support of pipelining (as well 00019 // as the sanity-check only implementation). 00020 00021 //////////////////////////////////////////////////////////////////// 00022 // Function: CycleDataLockedStageReader::Constructor (full) 00023 // Access: Public 00024 // Description: 00025 //////////////////////////////////////////////////////////////////// 00026 template<class CycleDataType> 00027 INLINE CycleDataLockedStageReader<CycleDataType>:: 00028 CycleDataLockedStageReader(const PipelineCycler<CycleDataType> &cycler, 00029 int stage, Thread *current_thread) : 00030 _cycler(&cycler), 00031 _current_thread(current_thread), 00032 _stage(stage) 00033 { 00034 _pointer = _cycler->read_stage(_stage, _current_thread); 00035 nassertv(_pointer != (const CycleDataType *)NULL); 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: CycleDataLockedStageReader::Copy Constructor (full) 00040 // Access: Public 00041 // Description: 00042 //////////////////////////////////////////////////////////////////// 00043 template<class CycleDataType> 00044 INLINE CycleDataLockedStageReader<CycleDataType>:: 00045 CycleDataLockedStageReader(const CycleDataLockedStageReader<CycleDataType> ©) : 00046 _cycler(copy._cycler), 00047 _current_thread(copy._current_thread), 00048 _pointer(copy._pointer), 00049 _stage(copy._stage) 00050 { 00051 nassertv(_pointer != (const CycleDataType *)NULL); 00052 _cycler->increment_read(_pointer); 00053 } 00054 00055 //////////////////////////////////////////////////////////////////// 00056 // Function: CycleDataLockedStageReader::Copy Assignment (full) 00057 // Access: Public 00058 // Description: 00059 //////////////////////////////////////////////////////////////////// 00060 template<class CycleDataType> 00061 INLINE void CycleDataLockedStageReader<CycleDataType>:: 00062 operator = (const CycleDataLockedStageReader<CycleDataType> ©) { 00063 nassertv(_pointer == (CycleDataType *)NULL); 00064 nassertv(_current_thread == copy._current_thread); 00065 00066 _cycler = copy._cycler; 00067 _pointer = copy._pointer; 00068 _stage = copy._stage; 00069 00070 nassertv(_pointer != (const CycleDataType *)NULL); 00071 _cycler->increment_read(_pointer); 00072 } 00073 00074 //////////////////////////////////////////////////////////////////// 00075 // Function: CycleDataLockedStageReader::Destructor (full) 00076 // Access: Public 00077 // Description: 00078 //////////////////////////////////////////////////////////////////// 00079 template<class CycleDataType> 00080 INLINE CycleDataLockedStageReader<CycleDataType>:: 00081 ~CycleDataLockedStageReader() { 00082 if (_pointer != NULL) { 00083 _cycler->release_read_stage(_stage, _pointer); 00084 } 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function: CycleDataLockedStageReader::operator -> (full) 00089 // Access: Public 00090 // Description: This provides an indirect member access to the actual 00091 // CycleData data. 00092 //////////////////////////////////////////////////////////////////// 00093 template<class CycleDataType> 00094 INLINE const CycleDataType *CycleDataLockedStageReader<CycleDataType>:: 00095 operator -> () const { 00096 nassertr(_pointer != (const CycleDataType *)NULL, _cycler->cheat()); 00097 return _pointer; 00098 } 00099 00100 //////////////////////////////////////////////////////////////////// 00101 // Function: CycleDataLockedStageReader::Typecast pointer (full) 00102 // Access: Public 00103 // Description: This allows the CycleDataLockedStageReader to be passed to any 00104 // function that expects a const CycleDataType pointer. 00105 //////////////////////////////////////////////////////////////////// 00106 template<class CycleDataType> 00107 INLINE CycleDataLockedStageReader<CycleDataType>:: 00108 operator const CycleDataType * () const { 00109 nassertr(_pointer != (const CycleDataType *)NULL, _cycler->cheat()); 00110 return _pointer; 00111 } 00112 00113 //////////////////////////////////////////////////////////////////// 00114 // Function: CycleDataLockedStageReader::take_pointer (full) 00115 // Access: Public 00116 // Description: This is intended to be called only from 00117 // CycleDataStageWriter when it elevates the pointer from 00118 // read to write status. This function returns the 00119 // reader's pointer and relinquishes ownership of the 00120 // pointer, rendering the reader invalid for future 00121 // reads. 00122 //////////////////////////////////////////////////////////////////// 00123 template<class CycleDataType> 00124 INLINE const CycleDataType *CycleDataLockedStageReader<CycleDataType>:: 00125 take_pointer() { 00126 const CycleDataType *pointer = _pointer; 00127 _pointer = (CycleDataType *)NULL; 00128 nassertr(pointer != (const CycleDataType *)NULL, _cycler->cheat()); 00129 return pointer; 00130 } 00131 00132 //////////////////////////////////////////////////////////////////// 00133 // Function: CycleDataLockedStageReader::get_current_thread (full) 00134 // Access: Public 00135 // Description: Returns the Thread pointer of the currently-executing 00136 // thread, as passed to the constructor of this object. 00137 //////////////////////////////////////////////////////////////////// 00138 template<class CycleDataType> 00139 INLINE Thread *CycleDataLockedStageReader<CycleDataType>:: 00140 get_current_thread() const { 00141 return _current_thread; 00142 } 00143 00144 #else // !DO_PIPELINING 00145 // This is the trivial, do-nothing implementation. 00146 00147 //////////////////////////////////////////////////////////////////// 00148 // Function: CycleDataLockedStageReader::Constructor (trivial) 00149 // Access: Public 00150 // Description: 00151 //////////////////////////////////////////////////////////////////// 00152 template<class CycleDataType> 00153 INLINE CycleDataLockedStageReader<CycleDataType>:: 00154 CycleDataLockedStageReader(const PipelineCycler<CycleDataType> &cycler, int, 00155 Thread *) { 00156 _pointer = cycler.cheat(); 00157 } 00158 00159 //////////////////////////////////////////////////////////////////// 00160 // Function: CycleDataLockedStageReader::Copy Constructor (trivial) 00161 // Access: Public 00162 // Description: 00163 //////////////////////////////////////////////////////////////////// 00164 template<class CycleDataType> 00165 INLINE CycleDataLockedStageReader<CycleDataType>:: 00166 CycleDataLockedStageReader(const CycleDataLockedStageReader<CycleDataType> ©) : 00167 _pointer(copy._pointer) 00168 { 00169 } 00170 00171 //////////////////////////////////////////////////////////////////// 00172 // Function: CycleDataLockedStageReader::Copy Assignment (trivial) 00173 // Access: Public 00174 // Description: 00175 //////////////////////////////////////////////////////////////////// 00176 template<class CycleDataType> 00177 INLINE void CycleDataLockedStageReader<CycleDataType>:: 00178 operator = (const CycleDataLockedStageReader<CycleDataType> ©) { 00179 _pointer = copy._pointer; 00180 } 00181 00182 //////////////////////////////////////////////////////////////////// 00183 // Function: CycleDataLockedStageReader::Destructor (trivial) 00184 // Access: Public 00185 // Description: 00186 //////////////////////////////////////////////////////////////////// 00187 template<class CycleDataType> 00188 INLINE CycleDataLockedStageReader<CycleDataType>:: 00189 ~CycleDataLockedStageReader() { 00190 } 00191 00192 //////////////////////////////////////////////////////////////////// 00193 // Function: CycleDataLockedStageReader::operator -> (trivial) 00194 // Access: Public 00195 // Description: This provides an indirect member access to the actual 00196 // CycleData data. 00197 //////////////////////////////////////////////////////////////////// 00198 template<class CycleDataType> 00199 INLINE const CycleDataType *CycleDataLockedStageReader<CycleDataType>:: 00200 operator -> () const { 00201 return _pointer; 00202 } 00203 00204 //////////////////////////////////////////////////////////////////// 00205 // Function: CycleDataLockedStageReader::Typecast pointer (trivial) 00206 // Access: Public 00207 // Description: This allows the CycleDataLockedStageReader to be passed to any 00208 // function that expects a const CycleDataType pointer. 00209 //////////////////////////////////////////////////////////////////// 00210 template<class CycleDataType> 00211 INLINE CycleDataLockedStageReader<CycleDataType>:: 00212 operator const CycleDataType * () const { 00213 return _pointer; 00214 } 00215 00216 //////////////////////////////////////////////////////////////////// 00217 // Function: CycleDataLockedStageReader::take_pointer (trivial) 00218 // Access: Public 00219 // Description: This is intended to be called only from 00220 // CycleDataStageWriter when it elevates the pointer from 00221 // read to write status. This function returns the 00222 // reader's pointer and relinquishes ownership of the 00223 // pointer, rendering the reader invalid for future 00224 // reads. 00225 //////////////////////////////////////////////////////////////////// 00226 template<class CycleDataType> 00227 INLINE const CycleDataType *CycleDataLockedStageReader<CycleDataType>:: 00228 take_pointer() { 00229 return _pointer; 00230 } 00231 00232 //////////////////////////////////////////////////////////////////// 00233 // Function: CycleDataLockedStageReader::get_current_thread (trivial) 00234 // Access: Public 00235 // Description: Returns the Thread pointer of the currently-executing 00236 // thread, as passed to the constructor of this object. 00237 //////////////////////////////////////////////////////////////////// 00238 template<class CycleDataType> 00239 INLINE Thread *CycleDataLockedStageReader<CycleDataType>:: 00240 get_current_thread() const { 00241 return Thread::get_current_thread(); 00242 } 00243 00244 #endif // DO_PIPELINING 00245 #endif // CPPPARSER