Panda3D
|
00001 // Filename: cycleDataLockedReader.h 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 CYCLEDATALOCKEDREADER_H 00016 #define CYCLEDATALOCKEDREADER_H 00017 00018 #include "pandabase.h" 00019 00020 #include "cycleData.h" 00021 #include "pipelineCycler.h" 00022 #include "thread.h" 00023 00024 //////////////////////////////////////////////////////////////////// 00025 // Class : CycleDataLockedReader 00026 // Description : This template class calls PipelineCycler::read() in 00027 // the constructor and PipelineCycler::release_read() in 00028 // the destructor. In the interim, it provides a 00029 // transparent read-only access to the CycleData. 00030 // 00031 // Since a lock is held on the data while the instance 00032 // of this class exists, no other thread may modify any 00033 // stage of the pipeline during that time. Thus, this 00034 // class is appropriate to use for cases in which you 00035 // might want to read and then modify the data. It is 00036 // possible to pass an instance of CycleDataLockedReader 00037 // to the CycleDataWriter constructor, which 00038 // automatically elevates the read lock into a write 00039 // lock. 00040 // 00041 // It exists as a syntactic convenience to access the 00042 // data in the CycleData. It also allows the whole 00043 // system to compile down to nothing if 00044 // DO_PIPELINING is not defined. 00045 //////////////////////////////////////////////////////////////////// 00046 template<class CycleDataType> 00047 class CycleDataLockedReader { 00048 public: 00049 // By hiding this template from interrogate, we improve compile-time 00050 // speed and memory utilization. 00051 #ifndef CPPPARSER 00052 INLINE CycleDataLockedReader(const PipelineCycler<CycleDataType> &cycler, 00053 Thread *current_thread = Thread::get_current_thread()); 00054 INLINE CycleDataLockedReader(const CycleDataLockedReader<CycleDataType> ©); 00055 INLINE void operator = (const CycleDataLockedReader<CycleDataType> ©); 00056 00057 INLINE ~CycleDataLockedReader(); 00058 00059 INLINE const CycleDataType *operator -> () const; 00060 INLINE operator const CycleDataType * () const; 00061 00062 INLINE const CycleDataType *take_pointer(); 00063 INLINE Thread *get_current_thread() const; 00064 00065 private: 00066 #ifdef DO_PIPELINING 00067 // This is the data stored for a real pipelining implementation. 00068 const PipelineCycler<CycleDataType> *_cycler; 00069 Thread *_current_thread; 00070 const CycleDataType *_pointer; 00071 CycleDataType *_write_pointer; 00072 #else // !DO_PIPELINING 00073 // This is all we need for the trivial, do-nothing implementation. 00074 const CycleDataType *_pointer; 00075 #endif // DO_PIPELINING 00076 #endif // CPPPARSER 00077 }; 00078 00079 #include "cycleDataLockedReader.I" 00080 00081 #endif