Panda3D
|
00001 // Filename: cycleDataWriter.I 00002 // Created by: drose (21Feb02) 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: CycleDataWriter::Constructor (full) 00023 // Access: Public 00024 // Description: 00025 //////////////////////////////////////////////////////////////////// 00026 template<class CycleDataType> 00027 INLINE CycleDataWriter<CycleDataType>:: 00028 CycleDataWriter(PipelineCycler<CycleDataType> &cycler, Thread *current_thread) : 00029 _cycler(&cycler), 00030 _current_thread(current_thread) 00031 { 00032 _pointer = _cycler->write(_current_thread); 00033 nassertv(_pointer != (CycleDataType *)NULL); 00034 } 00035 00036 //////////////////////////////////////////////////////////////////// 00037 // Function: CycleDataWriter::Constructor (full) 00038 // Access: Public 00039 // Description: This two-parameter constructor, with a bool parameter 00040 // for the second parameter, automatically propagates 00041 // the CycleData pointer upstream from the current 00042 // stage, either stopping at the first pointer 00043 // encountered that's different, going or all the way to 00044 // stage 0, according to force_to_0. See 00045 // PipelineCycler::write_upstream(). 00046 //////////////////////////////////////////////////////////////////// 00047 template<class CycleDataType> 00048 INLINE CycleDataWriter<CycleDataType>:: 00049 CycleDataWriter(PipelineCycler<CycleDataType> &cycler, bool force_to_0, 00050 Thread *current_thread) : 00051 _cycler(&cycler), 00052 _current_thread(current_thread) 00053 { 00054 _pointer = _cycler->write_upstream(force_to_0, _current_thread); 00055 nassertv(_pointer != (CycleDataType *)NULL); 00056 } 00057 00058 //////////////////////////////////////////////////////////////////// 00059 // Function: CycleDataWriter::Constructor (full) 00060 // Access: Public 00061 // Description: This special constructor "steals" a reference count 00062 // from the already-locked cdata object. It does not 00063 // increment the lock count of this object, but will 00064 // release it when the destructor is called. 00065 // 00066 // This is designed for special functions that return an 00067 // already-locked cdata object and expect the caller to 00068 // unlock it. 00069 //////////////////////////////////////////////////////////////////// 00070 template<class CycleDataType> 00071 INLINE CycleDataWriter<CycleDataType>:: 00072 CycleDataWriter(PipelineCycler<CycleDataType> &cycler, CycleDataType *locked_cdata, 00073 Thread *current_thread) : 00074 _cycler(&cycler), 00075 _current_thread(current_thread) 00076 { 00077 _pointer = locked_cdata; 00078 nassertv(_pointer != (CycleDataType *)NULL); 00079 } 00080 00081 //////////////////////////////////////////////////////////////////// 00082 // Function: CycleDataWriter::Copy Constructor (full) 00083 // Access: Public 00084 // Description: 00085 //////////////////////////////////////////////////////////////////// 00086 template<class CycleDataType> 00087 INLINE CycleDataWriter<CycleDataType>:: 00088 CycleDataWriter(const CycleDataWriter<CycleDataType> ©) : 00089 _cycler(copy._cycler), 00090 _current_thread(copy._current_thread), 00091 _pointer(copy._pointer) 00092 { 00093 nassertv(_pointer != (CycleDataType *)NULL); 00094 _cycler->increment_write(_pointer); 00095 } 00096 00097 //////////////////////////////////////////////////////////////////// 00098 // Function: CycleDataWriter::Copy Assignment (full) 00099 // Access: Public 00100 // Description: 00101 //////////////////////////////////////////////////////////////////// 00102 template<class CycleDataType> 00103 INLINE void CycleDataWriter<CycleDataType>:: 00104 operator = (const CycleDataWriter<CycleDataType> ©) { 00105 nassertv(_pointer == (CycleDataType *)NULL); 00106 nassertv(_current_thread == copy._current_thread); 00107 00108 _cycler = copy._cycler; 00109 _pointer = copy._pointer; 00110 00111 nassertv(_pointer != (CycleDataType *)NULL); 00112 _cycler->increment_write(_pointer); 00113 } 00114 00115 //////////////////////////////////////////////////////////////////// 00116 // Function: CycleDataWriter::Constructor (full) 00117 // Access: Public 00118 // Description: This flavor of the constructor elevates the pointer 00119 // from the CycleDataLockedReader from a read to a write 00120 // pointer (and invalidates the reader). 00121 //////////////////////////////////////////////////////////////////// 00122 template<class CycleDataType> 00123 INLINE CycleDataWriter<CycleDataType>:: 00124 CycleDataWriter(PipelineCycler<CycleDataType> &cycler, 00125 CycleDataLockedReader<CycleDataType> &take_from) : 00126 _cycler(&cycler), 00127 _current_thread(take_from.get_current_thread()) 00128 { 00129 _pointer = _cycler->elevate_read(take_from.take_pointer(), _current_thread); 00130 } 00131 00132 //////////////////////////////////////////////////////////////////// 00133 // Function: CycleDataWriter::Constructor (full) 00134 // Access: Public 00135 // Description: This flavor of the constructor elevates the pointer 00136 // from the CycleDataLockedReader from a read to a write 00137 // pointer (and invalidates the reader). It also 00138 // propagates the pointer back upstream; see 00139 // PipelineCycler::write_upstream(). 00140 //////////////////////////////////////////////////////////////////// 00141 template<class CycleDataType> 00142 INLINE CycleDataWriter<CycleDataType>:: 00143 CycleDataWriter(PipelineCycler<CycleDataType> &cycler, 00144 CycleDataLockedReader<CycleDataType> &take_from, 00145 bool force_to_0) : 00146 _cycler(&cycler), 00147 _current_thread(take_from.get_current_thread()) 00148 { 00149 _pointer = _cycler->elevate_read_upstream(take_from.take_pointer(), 00150 force_to_0, _current_thread); 00151 } 00152 00153 //////////////////////////////////////////////////////////////////// 00154 // Function: CycleDataWriter::Destructor (full) 00155 // Access: Public 00156 // Description: 00157 //////////////////////////////////////////////////////////////////// 00158 template<class CycleDataType> 00159 INLINE CycleDataWriter<CycleDataType>:: 00160 ~CycleDataWriter() { 00161 if (_pointer != (CycleDataType *)NULL) { 00162 _cycler->release_write(_pointer); 00163 } 00164 } 00165 00166 //////////////////////////////////////////////////////////////////// 00167 // Function: CycleDataWriter::operator -> (full) 00168 // Access: Public 00169 // Description: This provides an indirect member access to the actual 00170 // CycleData data. 00171 //////////////////////////////////////////////////////////////////// 00172 template<class CycleDataType> 00173 INLINE CycleDataType *CycleDataWriter<CycleDataType>:: 00174 operator -> () { 00175 nassertr(_pointer != (CycleDataType *)NULL, _cycler->cheat()); 00176 return _pointer; 00177 } 00178 00179 //////////////////////////////////////////////////////////////////// 00180 // Function: CycleDataWriter::operator -> (full) 00181 // Access: Public 00182 // Description: This provides an indirect member access to the actual 00183 // CycleData data. 00184 //////////////////////////////////////////////////////////////////// 00185 template<class CycleDataType> 00186 INLINE const CycleDataType *CycleDataWriter<CycleDataType>:: 00187 operator -> () const { 00188 nassertr(_pointer != (CycleDataType *)NULL, _cycler->cheat()); 00189 return _pointer; 00190 } 00191 00192 //////////////////////////////////////////////////////////////////// 00193 // Function: CycleDataWriter::Typecast pointer (full) 00194 // Access: Public 00195 // Description: This allows the CycleDataWriter to be passed to any 00196 // function that expects a CycleDataType pointer. 00197 //////////////////////////////////////////////////////////////////// 00198 template<class CycleDataType> 00199 INLINE CycleDataWriter<CycleDataType>:: 00200 operator CycleDataType * () { 00201 nassertr(_pointer != (CycleDataType *)NULL, _cycler->cheat()); 00202 return _pointer; 00203 } 00204 00205 //////////////////////////////////////////////////////////////////// 00206 // Function: CycleDataWriter::get_current_thread (full) 00207 // Access: Public 00208 // Description: Returns the Thread pointer of the currently-executing 00209 // thread, as passed to the constructor of this object. 00210 //////////////////////////////////////////////////////////////////// 00211 template<class CycleDataType> 00212 INLINE Thread *CycleDataWriter<CycleDataType>:: 00213 get_current_thread() const { 00214 return _current_thread; 00215 } 00216 00217 #else // !DO_PIPELINING 00218 // This is the trivial, do-nothing implementation. 00219 00220 //////////////////////////////////////////////////////////////////// 00221 // Function: CycleDataWriter::Constructor (trivial) 00222 // Access: Public 00223 // Description: 00224 //////////////////////////////////////////////////////////////////// 00225 template<class CycleDataType> 00226 INLINE CycleDataWriter<CycleDataType>:: 00227 CycleDataWriter(PipelineCycler<CycleDataType> &cycler, Thread *) { 00228 _pointer = cycler.cheat(); 00229 } 00230 00231 //////////////////////////////////////////////////////////////////// 00232 // Function: CycleDataWriter::Constructor (trivial) 00233 // Access: Public 00234 // Description: 00235 //////////////////////////////////////////////////////////////////// 00236 template<class CycleDataType> 00237 INLINE CycleDataWriter<CycleDataType>:: 00238 CycleDataWriter(PipelineCycler<CycleDataType> &cycler, bool, Thread *) { 00239 _pointer = cycler.cheat(); 00240 } 00241 00242 //////////////////////////////////////////////////////////////////// 00243 // Function: CycleDataWriter::Constructor (trivial) 00244 // Access: Public 00245 // Description: 00246 //////////////////////////////////////////////////////////////////// 00247 template<class CycleDataType> 00248 INLINE CycleDataWriter<CycleDataType>:: 00249 CycleDataWriter(PipelineCycler<CycleDataType> &, CycleDataType *locked_cdata, 00250 Thread *) { 00251 _pointer = locked_cdata; 00252 } 00253 00254 //////////////////////////////////////////////////////////////////// 00255 // Function: CycleDataWriter::Copy Constructor (trivial) 00256 // Access: Public 00257 // Description: 00258 //////////////////////////////////////////////////////////////////// 00259 template<class CycleDataType> 00260 INLINE CycleDataWriter<CycleDataType>:: 00261 CycleDataWriter(const CycleDataWriter<CycleDataType> ©) : 00262 _pointer(copy._pointer) 00263 { 00264 } 00265 00266 //////////////////////////////////////////////////////////////////// 00267 // Function: CycleDataWriter::Copy Assignment (trivial) 00268 // Access: Public 00269 // Description: 00270 //////////////////////////////////////////////////////////////////// 00271 template<class CycleDataType> 00272 INLINE void CycleDataWriter<CycleDataType>:: 00273 operator = (const CycleDataWriter<CycleDataType> ©) { 00274 _pointer = copy._pointer; 00275 } 00276 00277 //////////////////////////////////////////////////////////////////// 00278 // Function: CycleDataWriter::Constructor (trivial) 00279 // Access: Public 00280 // Description: This flavor of the constructor elevates the pointer 00281 // from the CycleDataLockedReader from a read to a write 00282 // pointer (and invalidates the reader). 00283 //////////////////////////////////////////////////////////////////// 00284 template<class CycleDataType> 00285 INLINE CycleDataWriter<CycleDataType>:: 00286 CycleDataWriter(PipelineCycler<CycleDataType> &, 00287 CycleDataLockedReader<CycleDataType> &take_from) : 00288 _pointer((CycleDataType *)take_from.take_pointer()) 00289 { 00290 } 00291 00292 //////////////////////////////////////////////////////////////////// 00293 // Function: CycleDataWriter::Constructor (trivial) 00294 // Access: Public 00295 // Description: This flavor of the constructor elevates the pointer 00296 // from the CycleDataLockedReader from a read to a write 00297 // pointer (and invalidates the reader). It also 00298 // propagates the pointer back upstream; see 00299 // PipelineCycler::write_upstream(). 00300 //////////////////////////////////////////////////////////////////// 00301 template<class CycleDataType> 00302 INLINE CycleDataWriter<CycleDataType>:: 00303 CycleDataWriter(PipelineCycler<CycleDataType> &, 00304 CycleDataLockedReader<CycleDataType> &take_from, 00305 bool force_to_0) : 00306 _pointer((CycleDataType *)take_from.take_pointer()) 00307 { 00308 } 00309 00310 //////////////////////////////////////////////////////////////////// 00311 // Function: CycleDataWriter::Destructor (trivial) 00312 // Access: Public 00313 // Description: 00314 //////////////////////////////////////////////////////////////////// 00315 template<class CycleDataType> 00316 INLINE CycleDataWriter<CycleDataType>:: 00317 ~CycleDataWriter() { 00318 } 00319 00320 //////////////////////////////////////////////////////////////////// 00321 // Function: CycleDataWriter::operator -> (trivial) 00322 // Access: Public 00323 // Description: This provides an indirect member access to the actual 00324 // CycleData data. 00325 //////////////////////////////////////////////////////////////////// 00326 template<class CycleDataType> 00327 INLINE CycleDataType *CycleDataWriter<CycleDataType>:: 00328 operator -> () { 00329 return _pointer; 00330 } 00331 00332 //////////////////////////////////////////////////////////////////// 00333 // Function: CycleDataWriter::operator -> (trivial) 00334 // Access: Public 00335 // Description: This provides an indirect member access to the actual 00336 // CycleData data. 00337 //////////////////////////////////////////////////////////////////// 00338 template<class CycleDataType> 00339 INLINE const CycleDataType *CycleDataWriter<CycleDataType>:: 00340 operator -> () const { 00341 return _pointer; 00342 } 00343 00344 //////////////////////////////////////////////////////////////////// 00345 // Function: CycleDataWriter::Typecast pointer (trivial) 00346 // Access: Public 00347 // Description: This allows the CycleDataWriter to be passed to any 00348 // function that expects a CycleDataType pointer. 00349 //////////////////////////////////////////////////////////////////// 00350 template<class CycleDataType> 00351 INLINE CycleDataWriter<CycleDataType>:: 00352 operator CycleDataType * () { 00353 return _pointer; 00354 } 00355 00356 //////////////////////////////////////////////////////////////////// 00357 // Function: CycleDataWriter::get_current_thread (trivial) 00358 // Access: Public 00359 // Description: Returns the Thread pointer of the currently-executing 00360 // thread, as passed to the constructor of this object. 00361 //////////////////////////////////////////////////////////////////// 00362 template<class CycleDataType> 00363 INLINE Thread *CycleDataWriter<CycleDataType>:: 00364 get_current_thread() const { 00365 return Thread::get_current_thread(); 00366 } 00367 00368 #endif // DO_PIPELINING 00369 #endif // CPPPARSER