Panda3D
cycleDataReader.h
1 // Filename: cycleDataReader.h
2 // Created by: drose (21Feb02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef CYCLEDATAREADER_H
16 #define CYCLEDATAREADER_H
17 
18 #include "pandabase.h"
19 
20 #include "cycleData.h"
21 #include "pipelineCycler.h"
22 #include "thread.h"
23 
24 ////////////////////////////////////////////////////////////////////
25 // Class : CycleDataReader
26 // Description : This template class calls
27 // PipelineCycler::read_unlocked(), and then provides a
28 // transparent read-only access to the CycleData. It is
29 // used to access the data quickly, without holding a
30 // lock, for a thread that does not intend to modify the
31 // data and write it back out. For cases where the data
32 // might be subsequently modified, you should use
33 // CycleDataLockedReader.
34 //
35 // It exists as a syntactic convenience to access the
36 // data in the CycleData. It also allows the whole
37 // system to compile down to nothing if
38 // DO_PIPELINING is not defined.
39 ////////////////////////////////////////////////////////////////////
40 template<class CycleDataType>
42 public:
43  // By hiding this template from interrogate, we improve compile-time
44  // speed and memory utilization.
45 #ifndef CPPPARSER
47  Thread *current_thread = Thread::get_current_thread());
48  INLINE CycleDataReader(const CycleDataReader<CycleDataType> &copy);
49  INLINE void operator = (const CycleDataReader<CycleDataType> &copy);
50 
51  INLINE ~CycleDataReader();
52 
53  INLINE const CycleDataType *operator -> () const;
54  INLINE operator const CycleDataType * () const;
55  INLINE const CycleDataType *p() const;
56 
57  INLINE Thread *get_current_thread() const;
58 
59 private:
60 #ifdef DO_PIPELINING
61  // This is the data stored for a real pipelining implementation.
62  const PipelineCycler<CycleDataType> *_cycler;
63  Thread *_current_thread;
64  const CycleDataType *_pointer;
65  CycleDataType *_write_pointer;
66 #else // !DO_PIPELINING
67  // This is all we need for the trivial, do-nothing implementation.
68  const CycleDataType *_pointer;
69 #endif // DO_PIPELINING
70 #endif // CPPPARSER
71 };
72 
73 #include "cycleDataReader.I"
74 
75 #endif
const CycleDataType * p() const
This allows the CycleDataReader to be passed to any function that expects a const CycleDataType point...
This class maintains different copies of a page of data between stages of the graphics pipeline (or a...
Thread * get_current_thread() const
Returns the Thread pointer of the currently-executing thread, as passed to the constructor of this ob...
static Thread * get_current_thread()
Returns a pointer to the currently-executing Thread object.
Definition: thread.I:145
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
A thread; that is, a lightweight process.
Definition: thread.h:51
const CycleDataType * operator->() const
This provides an indirect member access to the actual CycleData data.