Panda3D

cycleDataLockedReader.I

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