00001 // Filename: cycleDataReader.h 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 CYCLEDATAREADER_H 00016 #define CYCLEDATAREADER_H 00017 00018 #include "pandabase.h" 00019 00020 #include "cycleData.h" 00021 #include "pipelineCycler.h" 00022 #include "thread.h" 00023 00024 //////////////////////////////////////////////////////////////////// 00025 // Class : CycleDataReader 00026 // Description : This template class calls 00027 // PipelineCycler::read_unlocked(), and then provides a 00028 // transparent read-only access to the CycleData. It is 00029 // used to access the data quickly, without holding a 00030 // lock, for a thread that does not intend to modify the 00031 // data and write it back out. For cases where the data 00032 // might be subsequently modified, you should use 00033 // CycleDataLockedReader. 00034 // 00035 // It exists as a syntactic convenience to access the 00036 // data in the CycleData. It also allows the whole 00037 // system to compile down to nothing if 00038 // DO_PIPELINING is not defined. 00039 //////////////////////////////////////////////////////////////////// 00040 template<class CycleDataType> 00041 class CycleDataReader { 00042 public: 00043 // By hiding this template from interrogate, we improve compile-time 00044 // speed and memory utilization. 00045 #ifndef CPPPARSER 00046 INLINE CycleDataReader(const PipelineCycler<CycleDataType> &cycler, 00047 Thread *current_thread = Thread::get_current_thread()); 00048 INLINE CycleDataReader(const CycleDataReader<CycleDataType> ©); 00049 INLINE void operator = (const CycleDataReader<CycleDataType> ©); 00050 00051 INLINE ~CycleDataReader(); 00052 00053 INLINE const CycleDataType *operator -> () const; 00054 INLINE operator const CycleDataType * () const; 00055 INLINE const CycleDataType *p() const; 00056 00057 INLINE Thread *get_current_thread() const; 00058 00059 private: 00060 #ifdef DO_PIPELINING 00061 // This is the data stored for a real pipelining implementation. 00062 const PipelineCycler<CycleDataType> *_cycler; 00063 Thread *_current_thread; 00064 const CycleDataType *_pointer; 00065 CycleDataType *_write_pointer; 00066 #else // !DO_PIPELINING 00067 // This is all we need for the trivial, do-nothing implementation. 00068 const CycleDataType *_pointer; 00069 #endif // DO_PIPELINING 00070 #endif // CPPPARSER 00071 }; 00072 00073 #include "cycleDataReader.I" 00074 00075 #endif