Panda3D

cycleDataWriter.I

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::Copy Constructor (full)
00060 //       Access: Public
00061 //  Description:
00062 ////////////////////////////////////////////////////////////////////
00063 template<class CycleDataType>
00064 INLINE CycleDataWriter<CycleDataType>::
00065 CycleDataWriter(const CycleDataWriter<CycleDataType> &copy) :
00066   _cycler(copy._cycler),
00067   _current_thread(copy._current_thread),
00068   _pointer(copy._pointer)
00069 {
00070   nassertv(_pointer != (CycleDataType *)NULL);
00071   _cycler->increment_write(_pointer);
00072 }
00073 
00074 ////////////////////////////////////////////////////////////////////
00075 //     Function: CycleDataWriter::Copy Assigment (full)
00076 //       Access: Public
00077 //  Description:
00078 ////////////////////////////////////////////////////////////////////
00079 template<class CycleDataType>
00080 INLINE void CycleDataWriter<CycleDataType>::
00081 operator = (const CycleDataWriter<CycleDataType> &copy) {
00082   nassertv(_pointer == (CycleDataType *)NULL);
00083   nassertv(_current_thread == copy._current_thread);
00084 
00085   _cycler = copy._cycler;
00086   _pointer = copy._pointer;
00087 
00088   nassertv(_pointer != (CycleDataType *)NULL);
00089   _cycler->increment_write(_pointer);
00090 }
00091 
00092 ////////////////////////////////////////////////////////////////////
00093 //     Function: CycleDataWriter::Constructor (full)
00094 //       Access: Public
00095 //  Description: This flavor of the constructor elevates the pointer
00096 //               from the CycleDataLockedReader from a read to a write
00097 //               pointer (and invalidates the reader).
00098 ////////////////////////////////////////////////////////////////////
00099 template<class CycleDataType>
00100 INLINE CycleDataWriter<CycleDataType>::
00101 CycleDataWriter(PipelineCycler<CycleDataType> &cycler,
00102                 CycleDataLockedReader<CycleDataType> &take_from) :
00103   _cycler(&cycler),
00104   _current_thread(take_from.get_current_thread())
00105 {
00106   _pointer = _cycler->elevate_read(take_from.take_pointer(), _current_thread);
00107 }
00108 
00109 ////////////////////////////////////////////////////////////////////
00110 //     Function: CycleDataWriter::Constructor (full)
00111 //       Access: Public
00112 //  Description: This flavor of the constructor elevates the pointer
00113 //               from the CycleDataLockedReader from a read to a write
00114 //               pointer (and invalidates the reader).  It also
00115 //               propagates the pointer back upstream; see
00116 //               PipelineCycler::write_upstream().
00117 ////////////////////////////////////////////////////////////////////
00118 template<class CycleDataType>
00119 INLINE CycleDataWriter<CycleDataType>::
00120 CycleDataWriter(PipelineCycler<CycleDataType> &cycler,
00121                 CycleDataLockedReader<CycleDataType> &take_from,
00122         bool force_to_0) :
00123   _cycler(&cycler),
00124   _current_thread(take_from.get_current_thread())
00125 {
00126   _pointer = _cycler->elevate_read_upstream(take_from.take_pointer(), 
00127                                             force_to_0, _current_thread);
00128 }
00129 
00130 ////////////////////////////////////////////////////////////////////
00131 //     Function: CycleDataWriter::Destructor (full)
00132 //       Access: Public
00133 //  Description:
00134 ////////////////////////////////////////////////////////////////////
00135 template<class CycleDataType>
00136 INLINE CycleDataWriter<CycleDataType>::
00137 ~CycleDataWriter() {
00138   if (_pointer != (CycleDataType *)NULL) {
00139     _cycler->release_write(_pointer);
00140   }
00141 }
00142 
00143 ////////////////////////////////////////////////////////////////////
00144 //     Function: CycleDataWriter::operator -> (full)
00145 //       Access: Public
00146 //  Description: This provides an indirect member access to the actual
00147 //               CycleData data.
00148 ////////////////////////////////////////////////////////////////////
00149 template<class CycleDataType>
00150 INLINE CycleDataType *CycleDataWriter<CycleDataType>::
00151 operator -> () {
00152   nassertr(_pointer != (CycleDataType *)NULL, _cycler->cheat());
00153   return _pointer;
00154 }
00155 
00156 ////////////////////////////////////////////////////////////////////
00157 //     Function: CycleDataWriter::operator -> (full)
00158 //       Access: Public
00159 //  Description: This provides an indirect member access to the actual
00160 //               CycleData data.
00161 ////////////////////////////////////////////////////////////////////
00162 template<class CycleDataType>
00163 INLINE const CycleDataType *CycleDataWriter<CycleDataType>::
00164 operator -> () const {
00165   nassertr(_pointer != (CycleDataType *)NULL, _cycler->cheat());
00166   return _pointer;
00167 }
00168 
00169 ////////////////////////////////////////////////////////////////////
00170 //     Function: CycleDataWriter::Typecast pointer (full)
00171 //       Access: Public
00172 //  Description: This allows the CycleDataWriter to be passed to any
00173 //               function that expects a CycleDataType pointer.
00174 ////////////////////////////////////////////////////////////////////
00175 template<class CycleDataType>
00176 INLINE CycleDataWriter<CycleDataType>::
00177 operator CycleDataType * () {
00178   nassertr(_pointer != (CycleDataType *)NULL, _cycler->cheat());
00179   return _pointer;
00180 }
00181 
00182 ////////////////////////////////////////////////////////////////////
00183 //     Function: CycleDataWriter::get_current_thread (full)
00184 //       Access: Public
00185 //  Description: Returns the Thread pointer of the currently-executing
00186 //               thread, as passed to the constructor of this object.
00187 ////////////////////////////////////////////////////////////////////
00188 template<class CycleDataType>
00189 INLINE Thread *CycleDataWriter<CycleDataType>::
00190 get_current_thread() const {
00191   return _current_thread;
00192 }
00193 
00194 #else  // !DO_PIPELINING
00195 // This is the trivial, do-nothing implementation.
00196 
00197 ////////////////////////////////////////////////////////////////////
00198 //     Function: CycleDataWriter::Constructor (trivial)
00199 //       Access: Public
00200 //  Description:
00201 ////////////////////////////////////////////////////////////////////
00202 template<class CycleDataType>
00203 INLINE CycleDataWriter<CycleDataType>::
00204 CycleDataWriter(PipelineCycler<CycleDataType> &cycler, Thread *) {
00205   _pointer = cycler.cheat();
00206 }
00207 
00208 ////////////////////////////////////////////////////////////////////
00209 //     Function: CycleDataWriter::Constructor (trivial)
00210 //       Access: Public
00211 //  Description: 
00212 ////////////////////////////////////////////////////////////////////
00213 template<class CycleDataType>
00214 INLINE CycleDataWriter<CycleDataType>::
00215 CycleDataWriter(PipelineCycler<CycleDataType> &cycler, bool, Thread *) {
00216   _pointer = cycler.cheat();
00217 }
00218 
00219 ////////////////////////////////////////////////////////////////////
00220 //     Function: CycleDataWriter::Copy Constructor (trivial)
00221 //       Access: Public
00222 //  Description:
00223 ////////////////////////////////////////////////////////////////////
00224 template<class CycleDataType>
00225 INLINE CycleDataWriter<CycleDataType>::
00226 CycleDataWriter(const CycleDataWriter<CycleDataType> &copy) :
00227   _pointer(copy._pointer)
00228 {
00229 }
00230 
00231 ////////////////////////////////////////////////////////////////////
00232 //     Function: CycleDataWriter::Copy Assigment (trivial)
00233 //       Access: Public
00234 //  Description:
00235 ////////////////////////////////////////////////////////////////////
00236 template<class CycleDataType>
00237 INLINE void CycleDataWriter<CycleDataType>::
00238 operator = (const CycleDataWriter<CycleDataType> &copy) {
00239   _pointer = copy._pointer;
00240 }
00241 
00242 ////////////////////////////////////////////////////////////////////
00243 //     Function: CycleDataWriter::Constructor (trivial)
00244 //       Access: Public
00245 //  Description: This flavor of the constructor elevates the pointer
00246 //               from the CycleDataLockedReader from a read to a write
00247 //               pointer (and invalidates the reader).
00248 ////////////////////////////////////////////////////////////////////
00249 template<class CycleDataType>
00250 INLINE CycleDataWriter<CycleDataType>::
00251 CycleDataWriter(PipelineCycler<CycleDataType> &,
00252                 CycleDataLockedReader<CycleDataType> &take_from) :
00253   _pointer((CycleDataType *)take_from.take_pointer())
00254 {
00255 }
00256 
00257 ////////////////////////////////////////////////////////////////////
00258 //     Function: CycleDataWriter::Constructor (trivial)
00259 //       Access: Public
00260 //  Description: This flavor of the constructor elevates the pointer
00261 //               from the CycleDataLockedReader from a read to a write
00262 //               pointer (and invalidates the reader).  It also
00263 //               propagates the pointer back upstream; see
00264 //               PipelineCycler::write_upstream().
00265 ////////////////////////////////////////////////////////////////////
00266 template<class CycleDataType>
00267 INLINE CycleDataWriter<CycleDataType>::
00268 CycleDataWriter(PipelineCycler<CycleDataType> &,
00269                 CycleDataLockedReader<CycleDataType> &take_from,
00270         bool force_to_0) :
00271   _pointer((CycleDataType *)take_from.take_pointer())
00272 {
00273 }
00274 
00275 ////////////////////////////////////////////////////////////////////
00276 //     Function: CycleDataWriter::Destructor (trivial)
00277 //       Access: Public
00278 //  Description:
00279 ////////////////////////////////////////////////////////////////////
00280 template<class CycleDataType>
00281 INLINE CycleDataWriter<CycleDataType>::
00282 ~CycleDataWriter() {
00283 }
00284 
00285 ////////////////////////////////////////////////////////////////////
00286 //     Function: CycleDataWriter::operator -> (trivial)
00287 //       Access: Public
00288 //  Description: This provides an indirect member access to the actual
00289 //               CycleData data.
00290 ////////////////////////////////////////////////////////////////////
00291 template<class CycleDataType>
00292 INLINE CycleDataType *CycleDataWriter<CycleDataType>::
00293 operator -> () {
00294   return _pointer;
00295 }
00296 
00297 ////////////////////////////////////////////////////////////////////
00298 //     Function: CycleDataWriter::operator -> (trivial)
00299 //       Access: Public
00300 //  Description: This provides an indirect member access to the actual
00301 //               CycleData data.
00302 ////////////////////////////////////////////////////////////////////
00303 template<class CycleDataType>
00304 INLINE const CycleDataType *CycleDataWriter<CycleDataType>::
00305 operator -> () const {
00306   return _pointer;
00307 }
00308 
00309 ////////////////////////////////////////////////////////////////////
00310 //     Function: CycleDataWriter::Typecast pointer (trivial)
00311 //       Access: Public
00312 //  Description: This allows the CycleDataWriter to be passed to any
00313 //               function that expects a CycleDataType pointer.
00314 ////////////////////////////////////////////////////////////////////
00315 template<class CycleDataType>
00316 INLINE CycleDataWriter<CycleDataType>::
00317 operator CycleDataType * () {
00318   return _pointer;
00319 }
00320 
00321 ////////////////////////////////////////////////////////////////////
00322 //     Function: CycleDataWriter::get_current_thread (trivial)
00323 //       Access: Public
00324 //  Description: Returns the Thread pointer of the currently-executing
00325 //               thread, as passed to the constructor of this object.
00326 ////////////////////////////////////////////////////////////////////
00327 template<class CycleDataType>
00328 INLINE Thread *CycleDataWriter<CycleDataType>::
00329 get_current_thread() const {
00330   return Thread::get_current_thread();
00331 }
00332 
00333 #endif  // DO_PIPELINING
00334 #endif  // CPPPARSER
 All Classes Functions Variables Enumerations